php.net |  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: 2022-06-05 13:48 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: houweling dot frank at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
---------------
<?php
// 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

Patches

Pull Requests

History

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 https://bugs.php.net/bug.php?id=51950
 [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] salathe@php.net
-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] salathe@php.net
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].

[1] https://www.php.net/manual/en/datetime.createfromformat.php
 [2022-06-05 13:48 UTC] derick@php.net
-Status: Re-Opened +Status: Wont fix
 [2022-06-05 13:48 UTC] derick@php.net
I am marking this as "won't fix", because you can instead parse this string by using the DateTime constructor instead. 

If you are still interested in having this feature, please file a new issue at https://github.com/php/php-src/issues/ with a well defined and explained use case.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC