How to get age from Date in blade file in Laravel ?

In this tutorial, I will give you an example of the “How to get age from Date in the blade file in Laravel“, So you can easily apply it with your laravel 5, laravel 6, laravel 7, and laravel 8 application.

First, what we’re doing here, This is the example :

get age from Date in blade file

We can calculate age using carbon in the Laravel application. So just see the example:

get age from Date in blade file

We got the stored date of birth in the database which is in this format Y-m-d,

At first, we will change the date format in the blade file (d-m-Y) to calculate age from date of birth using strtotime in Laravel.

<label>DOB:</label>
<span>{{ date('d-m-Y', strtotime($viewdata->dob)) }}</span> 
<label>Age:</label>
<span>
{{ \Carbon\Carbon::parse($data->dob)->diff(\Carbon\Carbon::now())->format('%y years') }}</span>

get age from Date in blade file

In this article, we learned “Calculate age from date in Blade file”, I hope this article will help you with your application Project.

Also Read : Email already exist in laravel using jQuery.

Hi, My name is Gaurav Pandey. I'm a Laravel developer, owner of 8Bityard. I live in Uttarakhand - India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Javascript, JQuery, Laravel, WordPress. connect@8bityard.com

Scroll to Top