elapsed time function - how do I convert it to only total seconds?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

    elapsed time function - how do I convert it to only total seconds?

    Below is a good elapsed time function I found. However, I'd like to return
    total seconds instead of broken down into days, hours, minutes & seconds.
    In other words, I want "125" instead of "2 minutes 5 seconds".

    Any ideas? Thanks very much!


    function calcElapsedTime ($time)
    { // calculate elapsed time (in seconds!)
    $diff = time()-$time;
    $daysDiff = floor($diff/60/60/24);
    $diff -= $daysDiff*60*60 *24;
    $hrsDiff = floor($diff/60/60);
    $diff -= $hrsDiff*60*60;
    $minsDiff = floor($diff/60);
    $diff -= $minsDiff*60;
    $secsDiff = $diff;
    return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h '.$minsDiff.'m
    '.$secsDiff.'s) ');
    }


  • Shawn Wilson

    #2
    Re: elapsed time function - how do I convert it to only total seconds?

    NotGiven wrote:[color=blue]
    >
    > Below is a good elapsed time function I found. However, I'd like to return
    > total seconds instead of broken down into days, hours, minutes & seconds.
    > In other words, I want "125" instead of "2 minutes 5 seconds".
    >
    > Any ideas? Thanks very much!
    >
    > function calcElapsedTime ($time)
    > { // calculate elapsed time (in seconds!)
    > $diff = time()-$time;
    > $daysDiff = floor($diff/60/60/24);
    > $diff -= $daysDiff*60*60 *24;
    > $hrsDiff = floor($diff/60/60);
    > $diff -= $hrsDiff*60*60;
    > $minsDiff = floor($diff/60);
    > $diff -= $minsDiff*60;
    > $secsDiff = $diff;
    > return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h '.$minsDiff.'m
    > '.$secsDiff.'s) ');
    > }[/color]


    function calcElapsedTime ($time)
    { // calculate elapsed time (in seconds!)
    return (time()-$time);
    }

    Regards,
    Shawn
    --
    Shawn Wilson
    shawn@glassgian t.com


    I have a spam filter. Please include "PHP" in the
    subject line to ensure I'll get your message.

    Comment

    Working...