|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75745 DateTime::createFromFormat "u" specifier not interpreted correctly
Submitted: 2017-12-28 20:36 UTC Modified: 2020-04-11 15:22 UTC
From: Assigned:
Status: Open Package: Date/time related
PHP Version: >=7.1.0 OS: Any
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:
New email:
PHP Version: OS:


 [2017-12-28 20:36 UTC]
The "u" specifier is documented as "microseconds" but is interpreted as "fraction of a second".

While this is not the correct behaviour, it is potentially a desirable behaviour, specifically one might expect to be able to interpret a date like `12:13:14.42` as having a fractional part.

I propose adding an "f" specifier (currently unused) which retains this old behaviour, and fixing "u" to work as documented.

Test script:
echo DateTime::createFromFormat('u', '42')->format('u');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-28 23:02 UTC]
-PHP Version: 7.1.12 +PHP Version: >=7.1.0
 [2020-04-11 15:22 UTC]
FWIW, the the v specifier (milliseconds) available as of PHP 7.3.0
behaves in the same way.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun May 22 11:05:45 2022 UTC