472,950 Members | 2,541 Online

# 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)');
}
Jul 17 '05 #1
1 12269
NotGiven wrote:

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)');
}

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

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

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

This thread has been closed and replies have been disabled. Please start a new discussion.