Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

The beginner's avatar

changing 'last_activity' format in query

Hi,

I'm trying to get the date of 'last_activty' column of the sessions table, in the correct date format like

year-month-day H:m:seconds

but i don't recognize the format of the 'time' in this column, so i don't know how to do it.

I'm trying to get it in a query by the way, so i will not use ' format->() '.

Thanks.

0 likes
6 replies
Sinnbeck's avatar

What is the current format in that column?

1 like
Sinnbeck's avatar

@The beginner Can you show an actual example? Copy paste the contents of one of the fields

1 like
tykus's avatar
tykus
Best Answer
Level 104

It is a timestamp, so the FROM_UNIXTIME function in mysql can convert to a datetime for you:

DB::table('sessions')->selectRaw('*, FROM_UNIXTIME(last_activity) as last_activity_datetime')->get();
1 like

Please or to participate in this conversation.