Bug #74332 [Asn->Csd]: DateTime::createFromFormat(date) adds current time; but no microseconds

From: Date: Fri, 20 May 2022 14:08:24 +0000
Subject: Bug #74332 [Asn->Csd]: DateTime::createFromFormat(date) adds current time; but no microseconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241562@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74332&edit=1 ID: 74332 Updated by: derick@php.net Reported by: sjon at hortensius dot net Summary: DateTime::createFromFormat(date) adds current time; but no microseconds -Status: Assigned +Status: Closed Type: Bug Package: Date/time related PHP Version: 7.1.3 Assigned To: derick Block user comment: N Private report: N New Comment: 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" Previous Comments: ------------------------------------------------------------------------ [2017-03-29 12:38:08] 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74332&edit=1

« previous php.bugs (#241562) next »