By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.