php.net |  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: daverandom@php.net Assigned:
Status: Closed Package: Date/time related
PHP Version: >=7.1.0 OS: Any
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: daverandom@php.net
New email:
PHP Version: OS:

 

 [2017-12-28 20:36 UTC] daverandom@php.net
Description:
------------
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:
----------------
000042

Actual result:
--------------
420000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-28 23:02 UTC] daverandom@php.net
-PHP Version: 7.1.12 +PHP Version: >=7.1.0
 [2020-04-11 15:22 UTC] cmb@php.net
FWIW, the the v specifier (milliseconds) available as of PHP 7.3.0
behaves in the same way.
 [2022-06-08 14:59 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/084a0039f62c982526dc7e4334f526b31ce2ff63
Log: Fixed bug #75745: DateTime::createFromFormat 'u' specifier not documented correctly
 [2022-06-08 14:59 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC