Change date format in blade template Change date format in blade template laravel laravel

Change date format in blade template


You have 3 ways to do this:

1) Using Laravel Model - Doesn't work well with dates below 1900. You can however fix this by making a few adjustments.

<td>{{$expenses->date->format('j F, Y')}}</td>

2) Using PHP strtotime - Doesn't work well with dates below 1900. You can however fix this by making a few adjustments.

{{ date('j F, Y', strtotime($expenses->date)) }}

3) Using Carbon - Works well with all dates so far

{{ \Carbon\Carbon::parse($expenses->date)->format('j F, Y') }}


This is a duplicate of change the date format in laravel view page you can easily doing this.

<td>{{ date('d-M-y', strtotime($expenses->date)) }}</td>


You can make use of date-mutators

Add date field to your model's dates array.

Expense.php

class Expense extends Model{    protected $dates = ['date', 'another_date_field'];    //other stuff}

In view file you can format the date field like,

{{ $expenses->date->format('d-m-Y') }} //01-05-2018

or

{{ $expenses->date->format('l jS \\of F Y h:i:s A') }} //Tuesday 1st of May 2018 01:04:00 PM