Skip to content

Instantly share code, notes, and snippets.

@mcfdn
Last active December 20, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfdn/6114079 to your computer and use it in GitHub Desktop.
Save mcfdn/6114079 to your computer and use it in GitHub Desktop.
date intervals for PHP < 5.3
<?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