note 90024 added to function.strtotime
| From: | dewi at dewimorgan dot com | Date: | Thu, 02 Apr 2009 08:29:56 +0000 |
| Subject: | note 90024 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152740@lists.php.net to get a copy of this message | ||
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:
$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.
----
Server IP: 92.48.74.199
Probable Submitter: 213.123.188.5
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/90024
Del: integrated -- https://master.php.net/note/delete/90024/integrated
Del: useless -- https://master.php.net/note/delete/90024/useless
Del: bad code -- https://master.php.net/note/delete/90024/bad+code
Del: spam -- https://master.php.net/note/delete/90024/spam
Del: non-english -- https://master.php.net/note/delete/90024/non-english
Del: in docs -- https://master.php.net/note/delete/90024/in+docs
Del: other reasons-- https://master.php.net/note/delete/90024
Reject -- https://master.php.net/note/reject/90024
Search -- https://master.php.net/manage/user-notes.php