Created
September 19, 2011 04:04
-
-
Save justinkelly/1225940 to your computer and use it in GitHub Desktop.
Get the number of seconds since Jan 1, 0001 in PHP
This file contains 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 | |
/* | |
* 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