|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79692 Creating DateTime from unixtime should support fractional seconds
Submitted: 2020-06-11 22:52 UTC Modified: 2022-06-04 17:22 UTC
From: eric at ericstern dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.4.7 OS: All
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: eric at ericstern dot com
New email:
PHP Version: OS:


 [2020-06-11 22:52 UTC] eric at ericstern dot com
PHP has supported fractional seconds apparently dating back to 5.2.2 - a bit over 13 years. However when trying to create a new DateTime or DateTimeImmutable object from a unix timestamp (via "@1591858149"), non-integer timestamps are not parsed and can throw an exception:  Exception: DateTime::__construct(): Failed to parse time string (@1591858149.085) at 

Since `new DateTime()` will have a fractional component set based on the system clock, and other constructor formats support it (example:, this inconsistency seems specific to unix timestamps and should be resolved

Test script:


$timestamp = 1591858149.085;
$dt = new DateTime("@$timestamp");
$dti = new DateTimeImmutable("@$timestamp");

Expected result:
No errors; created objects correctly store the microseconds component from the timestamp.

Actual result:
Exception was thrown.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-11 23:47 UTC]
-Status: Open +Status: Not a bug
 [2020-06-11 23:47 UTC]
A unix timestamp by definition does not allow fractions:

>  the number of **seconds** that have elapsed since the Unix epoch
 [2020-06-11 23:48 UTC]
-Status: Not a bug +Status: Open -Type: Bug +Type: Feature/Change Request
 [2020-06-12 00:29 UTC] eric at ericstern dot com
> A unix timestamp by definition does not allow fractions:

> >  the number of **seconds** that have elapsed since the Unix epoch

This in no way conflicts with that definition - it states nothing about the number being an integer, and numerous sources exist showing fractional timestamps (notably including the Wikipedia entry on unixtime). It does conflict with several touch points in PHP, though, and I'm certainly not advocating for e.g. modifying the return type of time().

Regardless, I appreciate this being left open and updated to a change request! I missed that option when opening the issue.
 [2021-11-11 11:13 UTC]
-Package: date_time +Package: Date/time related
 [2022-06-04 17:22 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2022-06-04 17:22 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

Support for this was added in PHP 8.0:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 27 20:01:30 2024 UTC