You can use CarbonInterval and convert it for humans. The cascade method converts seconds to days, hours, minutes.
CarbonInterval::seconds($duration['time_spent'])->cascade()->forHumans();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my Laravel-8, I have this in my view blade:
{{$duration['time_spent'] ?? '' }}
time_spent is in seconds. How do I convert it to hours in human readable
For instance, 4 Hours 20 Minutes
time_spent is something like: 124323.4
When I did
{{$duration['time_spent']->diffForHumans() ?? '' }}
I got this error:
Call to a member function diffForHumans() on float
How do I resolve it?
Thanks
Sometimes try to find the answer in the documentation or look to the old post here.
Just three hours ago was here this thread
https://laracasts.com/discuss/channels/laravel/using-carbon-to-convert-second-to-time
Please or to participate in this conversation.