laravel carbon calculate age
Hi Guys,
In this example,I will learn you how to calculate carbon age in laravel.you can simply to calculate in laravel.
your birth date is around 1999-12-20 and today date like 2019-12-23 then it should be return 20 years old you are.So just see example
Example 1 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$dateOfBirth = '1999-12-20';
$years = \Carbon\Carbon::parse($dateOfBirth)->age;
dd($years);
}
Output
20 //years
Example 2 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$dateOfBirth = '1999-12-20';
$years = \Carbon\Carbon::parse($dateOfBirth)->diff(\Carbon\Carbon::now())->format('%y years, %m months and %d days');
dd($years);
}
Output
"20 years, 0 months and 3 days"
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial