|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74332 DateTime::createFromFormat(date) adds current time; but no microseconds
Submitted: 2017-03-29 12:38 UTC Modified: 2022-05-20 14:08 UTC
Avg. Score:3.5 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: sjon at hortensius dot net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.3 OS:
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:
From: sjon at hortensius dot net
New email:
PHP Version: OS:


 [2017-03-29 12:38 UTC] sjon at hortensius dot net
"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. "

Given that all datetime methods now include microseconds, DateTime::createFromFormat should do this as well

Test script:
var_dump(DateTime::createFromFormat('Y-m-d', '1980-01-01')->format('H:i:s.u'));

Expected result:
string(15) "14:35:58.283437"

Actual result:
string(15) "14:35:58.000000"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-30 13:14 UTC]
-Assigned To: +Assigned To: derick
 [2022-05-20 14:08 UTC]
-Status: Assigned +Status: Closed
 [2022-05-20 14:08 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

This seems to have been fixed some time ago, as in PHP 8.0.18 this shows:

$ sapi/cli/php
var_dump(DateTime::createFromFormat('Y-m-d', '1980-01-01')->format('H:i:s.u'));

string(15) "14:07:35.000000"
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 12:01:26 2023 UTC