Bug #66561 [Nab]: DateTime::createFromFormat wrong date for format 'jmY'

From: Date: Thu, 23 Jan 2014 13:48:19 +0000
Subject: Bug #66561 [Nab]: DateTime::createFromFormat wrong date for format 'jmY'
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183973@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66561&edit=1 ID: 66561 Updated by: salathe@php.net Reported by: claudia dot schmidt at archomedia dot com Summary: DateTime::createFromFormat wrong date for format 'jmY' Status: Not a bug Type: Bug Package: Date/time related PHP Version: 5.4.24 Block user comment: N Private report: N New Comment: 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". Previous Comments: ------------------------------------------------------------------------ [2014-01-23 13:41:40] 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:28:00] 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 12:57:45] 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66561&edit=1

« previous php.bugs (#183973) next »