|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63222 DateTime::createFromFormat() wrong with reset and D,l
Submitted: 2012-10-05 12:28 UTC Modified: 2021-07-14 11:09 UTC
From: gron1987 at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.4.7 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
1 + 43 = ?
Subscribe to this entry?

 [2012-10-05 12:28 UTC] gron1987 at gmail dot com
We found that createFromFormat work incorrect.
If we use reset in format ("!") and don't send year then we will receive new date 
in 1970 year, php don't change day of week ("Wed"), it change day("05").

It work correct in 5.3.8

Maybe you broke this when fix this:

Test script:
$str = "6:15 pm Wed, Oct 5";
$date = DateTime::createFromFormat("!g:i a D, M d", $str);

Expected result:
class DateTime#1 (3) {
  public $date =>
  string(19) "1970-10-05 18:15:00"
  public $timezone_type =>
  public $timezone =>
  string(13) "Europe/Berlin"

(php 5.3.8)

Actual result:
object(DateTime)#1 (3) {
  string(19) "1970-10-07 18:15:00"
  string(15) "Europe/Helsinki"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-14 11:09 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-07-14 11:09 UTC]
> in 1970 year, php don't change day of week ("Wed"), it change
> day("05").

Well, garbage in – garbage out.  Obviously, 1970-10-05 is not a
Wednesday (but a Monday) so there is no single correct solution;
either the day of the week is adjusted, or the the day of the
month.  Another option would be to fail.  However, the date parser
is quite liberal, and chooses to adjust the day of the month as of
PHP 5.3.9.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Sep 23 01:03:33 2021 UTC