Skip to content
Advertisement

Displaying date portion of timestamp in laravel field

I have a table data value in my laravel blade:

<td>{{$events->updated_at}}</td>

which just reads from a database timestamp value. It works and displays as it should but the controller is reading the full timestamp, which we need, but in this table data cell I only want to display the date portion.

So instead of 2017-12-27-00:00:00, I just want to show 2017-12-27.

Is there a special way I should go about this in a laravel blade?

Advertisement

Answer

All the timestamps in an Eloquent object use the Carbon class, making formatting easier. So all you have to do is use the Carbon format functions:

<td>{{$events->updated_at->toDateString()}}</td>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement