Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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