Showing problem with created_at value

I am trying to display the created_at column in one of my views and I have no luck. When I try to use below:

{{ date('d MY - H:i:s', $object->created_at) }}

I get the following error: date () expects parameter 2 to be a long, given object. So I use dd () on $ object-> created_at, and this gives me the following:

object(Carbon\Carbon)#555 (3) { ["date"]=> string(26) "2015-01-22 14:36:37.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Africa/Johannesburg" }

So naturally, I tried to access the date with a foreach loop that didn't work, and I also tried the date $ object-> created_at->, which gave me the error "Unknown getter 'date" How to access the date from created_at?

+8
laravel laravel-4 php-carbon
source share
2 answers

Laravel uses Carbon. Then try the following:

 {{ date('d MY - H:i:s', $object->created_at->timestamp) }} 

Or is it the same without a date function

 {{ $object->created_at->format('d MY - H:i:s') }} 

Or use any method described in the Carbon API

+10
source share

This is a different method -

 {{ date('F d, Y', strtotime($list->created_at)) }} 
+1
source share

All Articles