|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67308 Serialize of DateTime truncates fractions of second
Submitted: 2014-05-20 10:19 UTC Modified: 2014-05-21 20:07 UTC
From: robert dot johnson at icap dot com Assigned: aharvey (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4.28 OS: XP sp3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: robert dot johnson at icap dot com
New email:
PHP Version: OS:


 [2014-05-20 10:19 UTC] robert dot johnson at icap dot com
DateTime fractions of a second are ignored when serialized.

A DateTime cannot be correctly serialized and unserialized.

Test script:
$floatTime = '1400580590.47359';

$nowtime = \DateTime::createFromFormat('U.u', $floatTime);

echo $nowtime->format('Y-m-d H:i:s.u T')."\r\n";

echo serialize($nowtime)."\r\n";

Expected result:
2014-05-20 10:09:50.473590 GMT+0000
O:8:"DateTime":3:{s:4:"date";s:19:"2014-05-20 10:09:50.473590";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}


Note: this serialized DateTime includes the fraction, and when it is passed to unserialize(), the fraction is correctly set in the resulting DateTime object.

Therefore unserialize() works, serialize() does not work.


Actual result:
2014-05-20 10:09:50.473590 GMT+0000
O:8:"DateTime":3:{s:4:"date";s:19:"2014-05-20 10:09:50";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-21 20:07 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: aharvey
 [2014-05-21 20:07 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 09:01:27 2023 UTC