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: 2020-09-23 08:35 UTC
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 01:01:23 2020 UTC