php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55743 date u - Microseconds (added in PHP 5.2.2)
Submitted: 2011-09-20 18:42 UTC Modified: 2012-08-03 01:57 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugzilla33 at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.0beta1 OS: All
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: bugzilla33 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-09-20 18:42 UTC] bugzilla33 at gmail dot com
Description:
------------
http://pl.php.net/manual/en/function.date.php
http://pl.php.net/manual/en/function.gmdate.php

Specification:

u - Microseconds (added in PHP 5.2.2) - Example: 654321


u formater do not works because second parameter (called timestamp) is int type
u formater will works if second parameter (called timestamp) is double (compatible with current int)

Please remove u formater useless or fix specyfication
or a better fix it int -> double (second parameter)

Test script:
---------------
<?=gmdate('u',12.13)?>
<?=date('u',12.13)?>

Expected result:
----------------
130000
130000

Actual result:
--------------
000000
000000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-23 13:29 UTC] bjori@php.net
-Status: Open +Status: Bogus
 [2011-09-23 13:29 UTC] bjori@php.net
"Note:

Since this function only accepts integer timestamps the u format character is 
only useful when using the date_format() function with user based timestamps 
created with date_create()."

See http://php.net/date
 [2012-08-02 14:03 UTC] jsuprock at gmail dot com
Hi, I've experienced this as well, but I do follow your explanation.  However, 
what is the reason for the documentation on this page still being incorrect?

http://us2.php.net/manual/en/function.date.php

It has been almost a year, and the page still suggests that the "u" formatter 
will work with date().

Thank you,

John
 [2012-08-02 14:21 UTC] salathe@php.net
The "u" format character does work for date(), it always gives the correct answer 
of "000000" for this function.  As explained here and on the date() page, date() 
itself works with whole seconds for the timestamp. If fractions of seconds are 
needed, use the DateTime class.

Again, the document is correct since the "u" format character exists and does 
output the number of milliseconds for a given timestamp. However, that number 
will always be none since date() works with integers, i.e. whole seconds, only.
 [2012-08-02 17:57 UTC] jsuprock at gmail dot com
Hi Salathe,

    I suspected that this was the case based on the API for date() at php.net 
and the NOTE section.  I'm not disagreeing, but my issue is mainly with the 
documentation... 

    So here's the part where I feel like I need to put in my 2 cents, and I do 
appreciate your ears regardless of the outcome.  (You have been great so far.)  
With respect to what the NOTE section states, it would probably make more sense 
to do the following:

  (1) Disable this formatting character for date() and gmdate(), and 
specifically remove the formatting character from the documentation on the 
date() page.

  (2) Update the DateTime::format() page with an explicit list of formatting 
characters including the "u".

After all, the "u" format character is completely useless in the context of 
date(), and it really should not be allowed at all.  I just think it causes more 
confusion is all...unless perhaps in the future all PHP date functions will 
accept microtime(true) (with a precision of 6) instead of time().

Sincerely,

John
 [2012-08-03 01:53 UTC] aharvey@php.net
-Status: Not a bug +Status: Assigned -Type: Bug +Type: Documentation Problem -Package: Date/time related +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2012-08-03 01:53 UTC] aharvey@php.net
We can make this slightly clearer, I think.
 [2012-08-03 01:56 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326951
Log: Clarify when the &quot;u&quot; format string actually does something useful, per doc bug
#55743 (date u - Microseconds (added in PHP 5.2.2)).
 [2012-08-03 01:57 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2012-08-03 01:57 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I've handled this purely within the date() page — given that pretty much everything else is shared between date() and DateTime::format(), I don't really want to go down the path of splitting the reference across pages.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 21:01:33 2025 UTC