|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2008-07-18 11:26 UTC] tj at systisoft dot com
 Description:
------------
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
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.