note 90024 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 03 Nov 2013 15:23:16 +0000 |
| Subject: | note 90024 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197413@lists.php.net to get a copy of this message | ||
Note Submitter: dewi at dewimorgan dot com
----
Fails for non-US dates where the ordering is uncertain, such as 01/02/2003 - parses this as Feb 1st,
rather than Jan 2nd.
If you are parsing dates for a non-US locale, you can flip these elements of your date:
<?php
$y = $_POST['date'];
if (preg_match('/^\s*(\d\d?)[^\w](\d\d?)[^\w](\d{1,4}\s*$)/', $y, $match)) {
$y = $match[2] . '/' . $match[1] . '/' . $match[3];
}
echo date('d # m # Y', strtotime($y));
?>
WARNING: Above only works for dates, and breaks for times: 12:30:01 will be converted to 30/12/01.
This absolutely ought to be a flag to strtotime(), either as a boolean "monthfirst" flag,
or a boolean "respect my locale" flag. Since it isn't, kludge is needed.