Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
International version of strtotime()
<?php
/**
* Version of strtotime() that doesn't use American dates.
*
* `strtotime()` interprets a date with slashes as American - i.e. m/d/y. So we
* replace all slashes with dashes, to stop it from doing this.
*
* @author chris barnes <chris@cjbarnes.co.uk>
* @link http://www.cjbarnes.co.uk/blog/2016-07-10-using-strtotime-outside-us/
*
* @param string $time A date/time string.
* @param int $now Optional. The timestamp which is used as a base for the
* calculation of relative dates.
* @return string The strtotime() output.
*/
function world_strtotime($time, $now = null) {
if (is_null($now)) {
$now = time();
}
$str = str_replace('/', '-', $time);
return strtotime($time, $now);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment