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

fbc's avatar
Level 2

Dealing with EPOCH unix timestamp?

I query a DB that has time stamps in UNIX TIMESTAMP and I want to print just the hour minute and seconds from the time stamp like hh:mm:ss.

My controller function queries the table like this:

        $latestfeed72 = Feed72::orderBy('time')->take(3)->get();

and passes it to the view via compact('latestfeed72')

Then in the blade-view I have this:

                @foreach ($latestfeed72 as $feed72)
                ['{{$feed72->time}}', {{$feed72->data}}],
                // ['2004',  1000],
                // ['2005',  1170],
                // ['2006',  660],
                // ['2007',  1030]
                @endforeach

however I am getting the UNIX TIMESTAMP like 1547665750.

Is there another function I could use? or helper? Maybe something that would allow me to do: {{$feed72->time->format(hh:mm:ss)}}???

I have no idea. Any ideas guys?

0 likes
2 replies
s4muel's avatar

add this to your Feed72 Model class:

public function getTimeAttribute($value)
{
    return Carbon\Carbon::createFromTimestamp($value)->format("H:i:s");
}

Please or to participate in this conversation.