Change the date format in blade file in Laravel

Change the date format in the blade file in Laravel

In this tutorial, I will give you an example of the “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, and laravel 8 application.

Change the date format in laravel view page :

We can change the stored date format from our model, 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

Change the date format in Laravel

Preview : After changing the date format

Change the date format in Laravel

We used <input type=”date” name=”dob”> in add.blade.php file to store the date of birth value in database.

change the date format in laravel view page

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> 
laravel date format dd/mm/yyyy

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>
laravel date format dd/month/yyyy

In this article, we learned “Change the date format in PHP and Laravel”, I hope this article will help you with your Laravel application Project.

Also Read : Get the day difference between the two dates in Laravel.