View Full Version : Converting TotalSeconds to Hours then Minutes then Seconds

09-02-2007, 04:41 PM
I have a var called $totalBuildSeconds which has a large integer in it representing a time in seconds.

I need to take that time in seconds and convert it into hours:minutes:seconds, each stored in their own vars $buildHours, $buildMinutes, $buildSeconds

I am able to get the hours and minutes.. but not the seconds...
I think my brain is starting to melt.

$buildHours = floor($totalBuildSeconds / 3600);
$buildMinutes = (($totalBuildSeconds % 3600)*60);
$buildSeconds = $totalBuildSeconds - ($buildMinutes * 60);

09-02-2007, 05:17 PM
I got it... I think this is the solution:

$buildHours = floor($totalBuildTimeInSeconds / 3600);
$buildMinutes = floor(($totalBuildTimeInSeconds - ($buildHours*3600))/60);
$buildSeconds = ($totalBuildTimeInSeconds - ($buildHours*3600) - ($buildMinutes*60));