php.net |  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
Votes:4
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sjon at hortensius dot net
New email:
PHP Version: OS:

 

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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

$ sapi/cli/php
<?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-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC