Created
March 23, 2017 13:07
-
-
Save BlaM/06c6c248279c602d80c04cf8661d345e to your computer and use it in GitHub Desktop.
PHP implementation of mysql's TO_DAYS() and FROM_DAYS() functions
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 | |
function TO_DAYS($date) { | |
if (is_numeric($date)) { | |
$res = 719528 + (int) ($date / 86400); | |
} else { | |
$TZ = date_default_timezone_get(); | |
date_default_timezone_set('UTC'); | |
$res = 719528 + (int) (strtotime($date) / 86400); | |
date_default_timezone_set($TZ); | |
} | |
return $res; | |
} | |
function FROM_DAYS($daystamp, $asTS = false) { | |
$ts = ($daystamp - 719528) * 86400; | |
return $asTS?$ts:gmdate('Y-m-d', $ts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment