Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Do you want to use the Laravel blade date format in the Laravel application?
In this tutorial, I will give you an example of “How to Change the date format in the blade file in Laravel“, So you can easily apply it with your laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9 application.
This step-by-step tutorial helps you learn change the date format in Laravel with the help of php date format function.
We can change the stored date format from our model, and controller, and directly in the blade file, In this example, we change the date format (‘d-m-y’) in our view blade file.
Preview: Before changing the date format
Preview : After changing the date format
We used <input type=”date” name=”dob”> in the add.blade.php file to store the date of birth value in the database.
Now, we want to change the date format which is fetched from the database. now we got 1994-08-05 {{ $viewdata->dob }}.
<label>DOB:</label> <span>{{ $viewdata->dob }}</span>
We can change or rearrange the format dd/mm/yyyy in the view blade file in Laravel.
<label>DOB:</label> <span>{{ date('d-m-Y', strtotime($viewdata->dob)) }}</span>
We can also modify the date format which is more readable and human-friendly (dd/month/yyyy) in the view blade file in Laravel.
<label>DOB:</label> <span>{{ date('j \\ F Y', strtotime($viewdata->dob)) }}</span>
I hope that this article helped you learn Laravel date format with Examples in Laravel. You may also want to check out our guide on how to change the date format in the entire laravel application using Macro defining once in the Laravel application.
Also Read: Get the day difference between the two dates in Laravel.