|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45554 Inconsistent behavior of the u format char
Submitted: 2008-07-18 11:26 UTC Modified: 2009-07-29 15:35 UTC
Avg. Score:4.3 ± 0.9
Reproduced:2 of 3 (66.7%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: tj at systisoft dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.*, 6CVS (2009-05-09) OS: *
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tj at systisoft dot com
New email:
PHP Version: OS:


 [2008-07-18 11:26 UTC] tj at systisoft dot com
The u format char behaves inconsistent.

1. In output the it uses 6 digits. When used in date_create_from_format it recognizes only up to 5 digits (though microseconds would be 6). So date_create_from_format('m-d-Y H:i:s T', $dateTime->format('m-d-Y H:i:s T')); will generate an error.

2. Though DateTime does not support microseconds (or does it?) and should cut them off it behaves very strange when parsing a date with fractional seconds.

Reproduce code:
$d = date_create_from_format("m-d-Y H:i:s.u T", "03-15-2005 12:22:29.00000 PST");
echo $d->format("m-d-Y H:i:s.u T");
$d = date_create_from_format("m-d-Y H:i:s.u T", "03-15-2005 12:22:29.00100 PST");
echo $d->format("m-d-Y H:i:s.u T");

Expected result:
03-15-2005 12:22:29.00000 PST
03-15-2005 12:22:29.00000 PST

Actual result:
03-15-2005 12:22:29.000000 PST
03-15-2005 12:22:29.100000000 PST


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-18 11:28 UTC] tj at systisoft dot com
Upsi, there should be 6 zeros in the microsecond part of the expected result.
 [2008-07-18 16:26 UTC] tj at systisoft dot com
It seems that I am not totally awake.

So date_create_from_format('m-d-Y H:i:s T', $dateTime->format('m-d-Y H:i:s T')); will generate an error.

should read:

So date_create_from_format('m-d-Y H:i:s.u T', $dateTime->format('m-d-Y H:i:s.u T')); will generate an error.
 [2009-07-29 15:35 UTC]
Automatic comment from SVN on behalf of derick
Log: - Fixed bug #45554 (Inconsistent behavior of the u format char).
 [2009-07-29 15:35 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Nov 27 02:05:54 2022 UTC