Last active
December 20, 2015 10:18
-
-
Save mcfdn/6114079 to your computer and use it in GitHub Desktop.
date intervals for PHP < 5.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function intervals($start, $end = 'now') | |
{ | |
$unixStart = strtotime($start); | |
$unixNow = strtotime($end); | |
$diff = $unixNow - $unixStart; | |
$days = (int) ($diff / 86400); | |
$hours = (int) ($diff / 3600); | |
$minutes = (int) ($diff / 60); | |
$seconds = $diff; | |
$mod_days = $days; | |
$mod_hours = ($hours%24); | |
$mod_minutes = ($minutes%60); | |
$mod_seconds = ($seconds%60); | |
return array( | |
'total_days' => $days, | |
'total_hours' => $hours, | |
'total_minutes' => $minutes, | |
'total_seconds' => $seconds, | |
'days' => $mod_days, | |
'hours' => $mod_hours, | |
'minutes' => $mod_minutes, | |
'seconds' => $mod_seconds | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment