How to get age from date of birth in laravel

How to get age from date of birth in laravel

Sometimes you need to show user’s age on your website or app but you don’t know their exact age but you have their date of birth.

If you have user’s date of birth then you can show them their age by using Carbon.

For example someone’s date of birth is 16/08/1996 then how old he/she will be on today’s date?

To get the current age you will need to use Carbon in laravel app.

Here is an example / code snippet:-

$dateOfBirth = '1996-08-16';
$years = \Carbon::parse($dateOfBirth)->age;
echo $age; // returns current age eg: 25

Leave a Reply