Date Diff in PHP

Thanks to Ryan Means, I have an easy way to find the difference between 2 dates/times in PHP.

[code lang=”php”]
<?PHP
define(‘SecInDay’,86400);
define(‘SecInHour’,3600);
define(‘SecInMin’,60);
$totalsec=XXXXXXX; //Replace the X’s with a int value of seconds
$daysarray = explode(".", ($totalsec/SecInDay));
$days = $daysarray[0];
$partdays = fmod($totalsec, SecInDay);
$hoursarray = explode(".", ($partdays/SecInHour));
$hours = $hoursarray[0];
$parthours = fmod($partdays, SecInHour);
$minarray = explode(".", ($parthours/SecInMin));
$min = $minarray[0];
$sec = fmod($parthours, SecInMin);
echo "days " . $days . " ";
echo "hours " . $hours . " ";
echo "minutes " . $min . " ";
echo "seconds " . $sec . " ";
?>
[/code]

This entry was posted in php. Bookmark the permalink.