Here's a function for you...
<?php
function crunchtime($difference) {
// Define our global variables that we are going to return from the function
global $years, $weeks, $hours, $days, $minutes, $seconds;
// Define our calculation variables
$minsec = 60;
$hoursec = 3600;
$daysec = 86400;
$weeksec = 604800;
$yearsec = 31536000;
// First, determine the number of years if needed
IF($difference >= $yearsec){
$years = floor($difference/$yearsec);
$difference = ($difference%$yearsec);
} else {
$years = 0;
}
// Second, determine the number of weeks if needed
IF($difference >= $weeksec){
$weeks = floor($difference/$weeksec);
$difference = ($difference%$weeksec);
} else {
$weeks = 0;
}
// Third, determine the number of days if needed
IF($difference >= $daysec){
$days = floor($difference/$daysec);
$difference = ($difference%$daysec);
} else {
$days = 0;
}
// Fourth, determine the number of hours if needed
IF($difference >= $hoursec){
$hours = floor($difference/$hoursec);
$difference = ($difference%$hoursec);
} else {
$hours = 0;
}
// Fifth, determine the number of minutes if needed
IF($difference >= $minsec){
$minutes = floor($difference/$minsec);
$difference = ($difference%$minsec);
} else {
$minutes = 0;
}
// Lastly, the remaining difference is the seconds
$seconds = $difference;
// OK, now return all of our values so we can use them later
return $years;
return $weeks;
return $days;
return $hours;
return $minutes;
return $seconds;
}
?>
Usage:
<?php
$difference = 937262536;
crunchtime($difference);
echo $years." years<br />";
echo $weeks." weeks<br />";
echo $days." days<br />";
echo $hours." hours<br />";
echo $minutes." minutes<br />";
echo $seconds." seconds<br />";
?>
Outputs:
29 years
37 weeks
3 days
22 hours
42 minutes
16 seconds