php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74753 Function "date_format()" displays "1000" milliseconds after "999"
Submitted: 2017-06-13 09:20 UTC Modified: 2017-09-29 15:11 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: iyeo at ya dot ru Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.6 OS: (x64):Windows 8.1, Xubuntu 16.04
Private report: No CVE-ID: None
 [2017-06-13 09:20 UTC] iyeo at ya dot ru
Description:
------------
Function date_format($now, "Y-m-d\TH:m:s.v") returns "1000" milliseconds after "999", but it must be a "000".

Test script:
---------------
<?php
for ($i = 0; $i < 3000; $i++) {
  $now = new DateTime();            
  $t = date_format($now, "Y-m-d\TH:m:s.v");
  echo $t . "<br>";
}
?>

Expected result:
----------------
2017-06-13T11:06:22.998
2017-06-13T11:06:22.999
2017-06-13T11:06:23.000

Actual result:
--------------
2017-06-13T11:06:22.998
2017-06-13T11:06:22.999
2017-06-13T11:06:22.1000
2017-06-13T11:06:23.000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-13 09:52 UTC] requinix@php.net
-Status: Open +Status: Verified -Package: *General Issues +Package: Date/time related
 [2017-06-13 09:52 UTC] requinix@php.net
Due to the rounding also being done this will happen for microseconds >= 0.999500. https://3v4l.org/NNDZV
 [2017-06-13 10:16 UTC] derick@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: derick
 [2017-09-29 15:11 UTC] salathe@php.net
-Status: Assigned +Status: Closed
 [2017-09-29 15:11 UTC] salathe@php.net
This appears to be fixed as of PHP 7.2.0rc1.

Example script:

  $dateTime = new \DateTime('2017-09-29 17:44:48.999600');
  var_dump($dateTime->format('Y-m-d H:i:s.v'));

Output for 7.0.0 to 7.2.0beta3:

  string(24) "2017-09-29 17:44:48.1000"

Output for 7.2.0rc1 to 7.2.0rc2:

  string(23) "2017-09-29 17:44:48.999"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC