Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created May 4, 2012 21:21
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 md2perpe/2597798 to your computer and use it in GitHub Desktop.
Save md2perpe/2597798 to your computer and use it in GitHub Desktop.
Convert seconds to years, days, hours, minutes and seconds
function sec2time($time)
{
if(!is_numeric($time))
return false;
$value = array(
'seconds' => 60,
'minutes' => 60,
'hours' => 24,
'days' => 365,
);
foreach ($value as $part => $count)
{
$value[$part] = $time % $count;
$time = floor($time / $count);
}
$value['years'] = $time;
return $value;
}
@md2perpe
Copy link
Author

md2perpe commented May 4, 2012

First version taken from from http://www.catswhocode.com/blog/10-super-useful-php-snippets
Later versions are my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment