Calculate age from date of birth in Laravel

September 11, 2018 | Category : Laravel PHP

Hi Guys,

Today, we will learn to calculate age from birthdate in laravel application. we will use carbon to calculate age in laravel.

Actually, yesterday i was working on my laravel 5 application and i require to display age from date of birth in laravel project. I thought i need to use date helper function on php. but i found carbon to calculate age in laravel and we don't require to install carbon in laravel because it is already installed.

So, here is a very simple example for age calculation in laravel.

Example:

$myDate = '1995-07-02';

$years = \Carbon::parse($myDate)->age;

dd($years);

Output:

23

I hope you found your best...