php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80141 Datetime::createFromFormat('c') fails with c formatted string
Submitted: 2020-09-23 08:05 UTC Modified: 2020-09-23 08:36 UTC
From: kylekatarnls at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 7.4.10 OS:
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: kylekatarnls at gmail dot com
New email:
PHP Version: OS:

 

 [2020-09-23 08:05 UTC] kylekatarnls at gmail dot com
Description:
------------
This bug relates to https://bugs.php.net/bug.php?id=72592 which has been closed as duplicated while it's different from the bug it's supposed to duplicate (64414).

Datetime::createFromFormat() return false and generates 2 errors in getLastErrors() when giving the format 'c' and a string that has actually be output with format('c').

Side note: it works fine when passing the format 'Y-m-d\TH:i:sP' to createFromFormat()

Test script:
---------------
var_dump(DateTime::createFromFormat('c', (new DateTime('2020-02-02'))->format('c')));
echo implode("\n", DateTime::getLastErrors()['errors']);

Expected result:
----------------
object(DateTime)#3 (3) {
  ["date"]=>
  string(26) "2020-02-02 00:00:00.000000"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}


Actual result:
--------------
false
The format separator does not match
Trailing data

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-23 08:26 UTC] cmb@php.net
According to the docs, ::createFromFormat() does not support the
'c' format.  Use DateTimeInterface::ATOM instead:
<https://3v4l.org/jf52r>.
 [2020-09-23 08:36 UTC] salathe@php.net
-Status: Open +Status: Duplicate
 [2020-09-23 08:36 UTC] salathe@php.net
Duplicate of #72592.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 14:01:27 2024 UTC