php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66561 DateTime::createFromFormat wrong date for format 'jmY'
Submitted: 2014-01-23 12:57 UTC Modified: 2014-01-23 13:48 UTC
From: claudia dot schmidt at archomedia dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.24 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: claudia dot schmidt at archomedia dot com
New email:
PHP Version: OS:

 

 [2014-01-23 12:57 UTC] claudia dot schmidt at archomedia dot com
Description:
------------
Trying to parse a date string with format "jmY" and time "1012013" results in a wrong DateTime object. If I put some separator between day and month everything is ok.

Test script:
---------------
$time = '1012013';
$format = 'jmY';
$date = \DateTime::createFromFormat($time, $format);

var_dump($date);

Expected result:
----------------
DateTime object representing "2013-01-01 13:51:54"

Actual result:
--------------
DateTime object representing "0013-12-10 13:51:54"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-23 13:28 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2014-01-23 13:28 UTC] salathe@php.net
If there are two digits available, the "j" format character will consume them. 

Bear in mind that the format characters for DateTime::createFromFormat() are not strictly the same as the format characters for date() or DateTime::format(); e.g. DateTime::createFromFormat() will accept a leading zero for "j", where that character will not produce a leading zero with date().
 [2014-01-23 13:41 UTC] claudia dot schmidt at archomedia dot com
So how is it possible to parse a date like '1012013'? The difference in meaning is a bit confusing.
 [2014-01-23 13:48 UTC] salathe@php.net
You can use some other format for the date string (e.g. with separators, or two-digit day of month) that will be parsed "correctly".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 12:01:28 2024 UTC