Rahul Vp
Rahul Vp

Reputation: 127

How to do timestamp to DateTime conversion in laravel 5

How can i change the timestamp format into dateTime format in laravel 5, while fetching the timestamp from the table.?

<td>{{ $nam->date("Y-m-d H:i:s", lastLoginTime) }}</td>

When I tried this one, its showing error "Call to undefined method stdClass::date()".
Anyone help me to solve it.

Upvotes: 1

Views: 4260

Answers (1)

Adam
Adam

Reputation: 455

In the Model you can add the below function to add dates to diffForHumans() function:

funtion getDates()
{
    return array('created_at', 'updated_at', 'lastLoginTime');
}

etc etc.

Or you can use the following:

{{ $nam->lastLoginTime->format('Y-m-d H:i:s') }}

Upvotes: 1

Related Questions