|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72592 Datetime::createFromFormat not working with ISO 8601 modifier 'c'
Submitted: 2016-07-13 11:19 UTC Modified: 2020-09-23 08:35 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: houweling dot frank at gmail dot com Assigned:
Status: Re-Opened Package: Date/time related
PHP Version: Irrelevant OS: All
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.
Block user comment
Status: Assign to:
Bug Type:
From: houweling dot frank at gmail dot com
New email:
PHP Version: OS:


 [2016-07-13 11:19 UTC] houweling dot frank at gmail dot com
I have tested this bug on Windows / Linux and PHP versions 5.5 and 7.0. The DateTime::createFromFormat function does not correctly use the ISO 8601 modifier ('c'). Trying to parse an ISO 8601 datetime string using this function results in 'false'.

Test script:
// Create datetime
$date = new \DateTime('now');
var_dump($date); // = DateTime Object

// Convert to string
$fDate = $date->format('c');
var_dump($fDate); // = ISO 8601 string

// Read data to object
$rDate = \DateTime::createFromFormat('c', $fDate);
var_dump($rDate); // = false

Expected result:
\DateTime::createFromFormat('c', $fDate); should result in a valid DateTime object, with the same contents as the original $date object.

Actual result:
False, the createFromFormat function cannot parse the string


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-13 11:26 UTC] houweling dot frank at gmail dot com
-Status: Open +Status: Closed
 [2016-07-13 11:26 UTC] houweling dot frank at gmail dot com
Duplicate of
 [2020-09-23 07:21 UTC] kylekatarnls at gmail dot com
Hello, this is not a duplicate of 51950, this last one is about decimal fractions, while `c` format does not output decimal and still fails in createFromFormat. Could you re-open please?
 [2020-09-23 08:35 UTC]
-Status: Closed +Status: Re-Opened -Type: Bug +Type: Feature/Change Request -Package: Unknown/Other Function +Package: Date/time related
 [2020-09-23 08:35 UTC]
Re-opened as this is a new feature request: to add support for the 'c' format, which is not currently one of the supported formats for DateTime::createFromFormat()[1].

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 22 05:03:37 2021 UTC