Skip to content

Instantly share code, notes, and snippets.

@justinkelly
Created September 19, 2011 04:04
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 justinkelly/1225940 to your computer and use it in GitHub Desktop.
Save justinkelly/1225940 to your computer and use it in GitHub Desktop.
Get the number of seconds since Jan 1, 0001 in PHP
<?php
/*
* Very simple way to get the number of seconds from Jan 1, 0001 or any other date
* the normal date/time functions only work from 1 Jan 1970
* Requires PHP 5.3 or above
* Start: must be in YYYY-MM-DD format
* End: must be in YYYY-MM-DD format
*/
function seconds_since($start='0001-01-01',$end=date(Y-m-d))
(
$datetime1 = new DateTime($start);
$datetime2 = new DateTime($end);
$interval = $datetime1->diff($datetime2);
return $interval->format('%a') * 24 * 60 * 60;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment