The gmtdate() function didn't work for me as I was tracking hours worked on a project and if it's over 24 hours, you get amount left over after 24 hours is subtracted. In other words 37 hours becomes 13 hours. (all as stated above by Glavic - thanks for your examples!)
This one worked well:
Convert seconds to format by 'foot' no limit :
$seconds = 8525;
$H = floor($seconds / 3600);
$i = ($seconds / 60) % 60;
$s = $seconds % 60;
echo sprintf("%02d:%02d:%02d", $H, $i, $s);
# 02:22:05
$given = 685;
/*
* In case $given == 86400, gmdate( "H" ) will convert it into '00' i.e. midnight.
* We would need to take this into consideration, and so we will first
* check the ratio of the seconds i.e. $given:$number_of_sec_in_a_day
* and then after multiplying it by the number of hours in a day (24), we
* will just use "floor" to get the number of hours as the rest would
* be the minutes and seconds anyways.
*
* We can also have minutes and seconds combined in one variable,
* e.g. $min_sec = gmdate( "i:s", $given );
* But for versatility sake, I have taken them separately.
*/
$hours = ( $given > 86399 ) ? '0'.floor( ( $given / 86400 ) * 24 )-gmdate( "H", $given ) : gmdate("H", $given );
$min = gmdate( "i", $given );
$sec = gmdate( "s", $given );
echo $formatted_string = $hours.':'.$min.':'.$sec;
here you go
The gmtdate() function didn't work for me as I was tracking hours worked on a project and if it's over 24 hours, you get amount left over after 24 hours is subtracted. In other words 37 hours becomes 13 hours. (all as stated above by Glavic - thanks for your examples!) This one worked well:
If you don't like accepted answer or popular once, then try this one
To convert it into a function:
write function like this to return an array
then simply call the function like this:
output is