Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Another TIME manipulation question. Please help.

    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 ??

    Thanks-a-bunch,
    ~ Mo
    Last edited by mOrloff; 11-08-2010 at 09:30 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #3
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Thanks.
    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.

    Thanks.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Basic:

    Code:
    $time = (97920/3600);
    print($time."\n");
    Just fiddle around with the output format a tad.

  • #5
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    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:
    PHP Code:
    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.
    Thanks-a-bunch,
    ~ Mo

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Looks good

  • #7
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    In case it can help anyone else, here's my cleaned-up version as a func.
    PHP Code:
    function secondsToTime($seconds){
        
    $result=array();
        
    $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
    Last edited by mOrloff; 11-08-2010 at 10:00 PM. Reason: Refined the func


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •