php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46993 strtotime inconsistently parses M-j-Y and Y-M-j format dates
Submitted: 2009-01-02 16:24 UTC Modified: 2009-07-29 17:52 UTC
From: anomie at users dot sourceforge dot net Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.*, 6CVS (2009-01-02) OS: Linux
Private report: No CVE-ID: None
 [2009-01-02 16:24 UTC] anomie at users dot sourceforge dot net
Description:
------------
M-j-Y format dates are parsed correctly if the day is 10-31, but as M-j-Hi if the day is 1-9. Or, you could say that M-j-Hi format dates are parsed correctly if the day is 1-9, but incorrectly if the day is 10-31.

Y-M-j format dates are parsed correctly if the day is 10-31, but as Y-M in the timezone UTC-j if the day is 1-9. Or, you could say that this odd method of specifying the time zone fails for UTC-10, UTC-11, and so on.

Both M-d-Y and Y-M-d formats are parsed correctly for all days.

I would find it more consistent if the M-j-Y and Y-M-j formats were recognized for all days, as the other option would conflict with M-d-Y and Y-M-d recognition and both "M-j-Hi" and "Y-M"-with-timezone seem to be unlikely input formats.

This bug is also present in PHP 5.2.6.

Reproduce code:
---------------
date_default_timezone_set("UTC");
echo date("Y-m-d H:i:s\n", strtotime("Dec-9-2006"));
echo date("Y-m-d H:i:s\n", strtotime("9-Dec-2006"));
echo date("Y-m-d H:i:s\n", strtotime("2006-Dec-9"));
echo date("Y-m-d H:i:s\n", strtotime("Dec-10-2006"));
echo date("Y-m-d H:i:s\n", strtotime("10-Dec-2006"));
echo date("Y-m-d H:i:s\n", strtotime("2006-Dec-10"));


Expected result:
----------------
2006-12-09 00:00:00
2006-12-09 00:00:00
2006-12-09 00:00:00
2006-12-10 00:00:00
2006-12-10 00:00:00
2006-12-10 00:00:00


Actual result:
--------------
2009-12-09 20:06:00
2006-12-09 00:00:00
2006-12-01 09:00:00
2006-12-10 00:00:00
2006-12-10 00:00:00
2006-12-10 00:00:00


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-29 17:52 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

THis is how the parser works, we can't anticipate *all* forms and changing this breaks other things.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 09:01:31 2024 UTC