How to Get Age from Date of Birth in Laravel
How to get age from date of birth in laravel is the todays tutorial. In this tutorial, I will share some ways to find age from date in php Laravel application. From date how to find age you will know from this example.
So I will show you many ways to find age from date. If you don't know how to find carbon get age from the date, then this example is for you. Sometimes we need to show calculate age from date of birth php laravel application.
So let's see the source code and example:
$birthDate = new DateTime('1992-05-25'); $currentDate = new DateTime('today'); echo $birthDate->diff($currentDate)->y;
This is another way to get age from date.
$birthDate = '1995-05-25'; // Your birthdate $currentYear = date('Y'); // Current Year $birthYear = date('Y', strtotime($birthDate)); $age = $currentYear - $birthYear; echo $age;
Using carbon, we can also get age from date in Laravel.
$birthDate = '1992-05-25'; $age = \Carbon\Carbon::parse($birthDate)->age;
Hope this code will help you.