View Full Version : Resolved Another TIME manipulation question. Please help.

11-08-2010, 03:07 PM
I have a count of seconds which I want to turn into hours and minutes.
The problem is, I only keep finding solutions which view hours through the hours-per-day lense. I just want a count.
For example, if I have 97,920 seconds, I want to print

27hrs 12mins
rather than

1day 3hrs 12mins

Is there a native function that can help here (or even a custom func or class someone can refer me to), or do I need to just invent this wheel myself :)??

~ Mo

11-08-2010, 04:23 PM
This is a case of inventing the wheel (though a very easy wheel to invent). There are no native functions that'll do this as far as I know or have found yet.

11-08-2010, 04:30 PM
The sad thing is I know I've already done it before but I just can't remember which project that was on.
It was nice and clean, and in a tidy little package. I think I'll try to dig around a little.


11-08-2010, 04:45 PM

$time = (97920/3600);

Just fiddle around with the output format a tad.

11-08-2010, 04:48 PM
I've found it !!!
After just a little bit of tweaking and clean up, it'll be perfect!

Here's a direct copy/paste what I found, in case anyone's interested:

if($dateSent){ // Use this to calc the turn-around time
$message.=', and the quote was completed only';
$diff=(time() - $dateSent);
if( $days=(floor($diff/86400)) ){$diff = $diff % 86400; $message.=" $days days,";} // if there are days, echo them
if( $hours=(floor($diff/3600)) ){$diff = $diff % 3600; $message.=" $hours hours,";} // if there are hrs, echo them
if( $minutes=(floor($diff/60)) ){$diff = $diff % 60; $message.=" $minutes minutes,";} // if there are min's, echo them
$message.=" $diff seconds from your email being SENT"; // tell how many seconds it took to process

Critiques are also welcome.
~ Mo

11-08-2010, 04:56 PM
Looks good :)

11-08-2010, 05:48 PM
In case it can help anyone else, here's my cleaned-up version as a func.

function secondsToTime($seconds){
$seconds_hourModulus = $seconds % 3600; // get the seconds which remain AFTER we take all the whole hours out
if( $days=(floor($seconds/86400)) ){$result['days']=$days;} // get the total count of days in the seconds provided
if( $hours=(floor($seconds/3600)) ){$result['hrs']=$hours;} // get the total count of hours in the seconds provided
if( $minutes=(floor($seconds/60)) ){$result['mins']=$minutes;} // get the total count of min's in the seconds provided
if( $modulusMinutes=(floor($seconds_hourModulus/60)) ){$result['modMins']=$modulusMinutes;} // get the minutes which remain after all the whole hours are removed
return $result;

Feel free to contribute/improve on this.

~ Mo