Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Carbon seconds to forHumans

I have a table with column seconds, where I insert online time (in seconds),

Carbon::parse($seconds)->forHumans();

Doesnt allow me to do this, there is a way to parse seconds and transfer it to humans reading? like 1 hour or 2 weeks?

like image 634
Froxz Avatar asked Nov 11 '15 06:11

Froxz


2 Answers

This should return the result you're after:

Carbon::now()->subSeconds($seconds)->diffForHumans();
like image 151
Maltronic Avatar answered Oct 15 '22 04:10

Maltronic


Try this:

Carbon Time in Human readable format

// $sec will be the value from your seconds table
echo Carbon::now()->addSeconds($sec)->diffForHumans();
// OR
echo Carbon::now()->subSeconds($sec)->diffForHumans();

Output

// if $sec = 5
5 seconds from now

Found this useful doc Carbon

Hope this is helpful.

like image 28
ArtisanBay Avatar answered Oct 15 '22 04:10

ArtisanBay