Use date_diff()
See https://www.php.net/manual/en/datetime.diff.php
$date1=date_create("now");
$date2=date_create("2013-12-12");
$diff=date_diff($date1, $date2);
dd($diff->y);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When the user registers on the website, the date of birth is stored in a string format, like this: 12/05/1990
I need to calculate the age of the user whenever he submits a new post on the site.
I saw that this function exists: STR_TO_DATE(str, format)
But I can't use it in laravel, and I also don't know how I could get the age using STR_TO_DATE(str, format)
How can I do this ?
Laravel use Carbon so it's really easy with this
use Carbon\Carbon;
$age = Carbon::parse('12/05/1990')->age;
Please or to participate in this conversation.