View Full Version : simple question with time() manipulation

07-10-2005, 03:51 AM
i have a bunch of logged time() values from around a week ago, and i want to calculate the difference between time() and that value like this:

$diff = time() - $pasttime;

the dilemma i am having with this is how to calculate how many days, hours, mins and seconds this difference is. help appreciated, this is reasonably urgent.

if you don't understand what i mean, i mean turning the difference which may be like 550392 (seconds) into something like 7 days, 3 hours, 28 mins, 51 secs.

07-10-2005, 04:10 AM
function countdown ($count) {
$difference = $count - time();
$abs_difference = abs($difference);

$days = floor($abs_difference/60/60/24);
$hours = floor(($abs_difference - $days*60*60*24)/60/60);
$minutes = floor(($abs_difference - $days*60*60*24 - $hours*60*60)/60);

if ($difference != $abs_difference) {
return "It was $days days, $hours hours and $minutes minutes ago!";
} else {
return "Only $days days, $hours hours and $minutes minutes to go!";


Should be simple enough to modify.

07-10-2005, 04:22 AM
thanks alot for that :)