|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77701 \DateTime::createFromFormat does not set default parts
Submitted: 2019-03-06 04:11 UTC Modified: 2022-05-20 14:52 UTC
From: zerkms at zerkms dot ru Assigned:
Status: Closed Package: Date/time related
PHP Version: 7.3.2 OS: linux
Private report: No CVE-ID: None
 [2019-03-06 04:11 UTC] zerkms at zerkms dot ru
As documentation says (

If format does not contain the character ! then portions of the generated time which are not specified in format will be set to the current system time.

While in php >= 7.3.0 it's not the case anymore. Date fractions are filled, but time are zeroed.

➜ docker run -v $(pwd):/app --rm php:7.2-cli php /app/dt.php
string(29) "2019-03-06T04:09:30.000+00:00"

➜ docker run -v $(pwd):/app --rm php:7.3-cli php /app/dt.php
string(29) "2019-03-06T00:00:00.000+00:00"

Test script:

$now = \DateTime::createFromFormat('u', 0);

var_dump(time(), $now->format(\DateTime::RFC3339_EXTENDED));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-06 04:23 UTC]
-Status: Open +Status: Verified
 [2022-05-20 14:52 UTC]
-Type: Bug +Type: Documentation Problem
 [2022-05-20 14:52 UTC]
I am marking this as Documentation Problems, as this behaviour is now long standing, and not only applicable for the 'u' character. The same behaviour occurs for other time related characters too.

We can break this behaviour again, but I am not really willing to do so.
 [2022-06-02 15:52 UTC]
Automatic comment on behalf of derickr
Log: Fixed bug #77701: DateTime::createFromFormat does not set default parts
 [2022-06-02 15:52 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 16:01:35 2024 UTC