|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71345 DateTime::__construct failed to parse fraction with more than 9 digits.
Submitted: 2016-01-12 06:22 UTC Modified: 2022-05-20 13:28 UTC
Avg. Score:4.4 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: iceberg_young at 126 dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0.2 OS: Any
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: iceberg_young at 126 dot com
New email:
PHP Version: OS:


 [2016-01-12 06:22 UTC] iceberg_young at 126 dot com
DateTime::__construct cannot parse [W3] datetime format with fraction of second has more than **9** digits.
	new \DateTime("2016-01-01T01:02:03.123456789-01:02");
will fail, while
	new \DateTime("2016-01-01T01:02:03.12345678-01:02");
is ok.

Tried PHP version: 5.5.26 and 7.0.2
Tried OS: CentOS 6.7, openSUSE Tumbleweed, Windows 7



Test script:
$w3 = new \DateTime("2016-01-01T01:02:03.123456789-01:02");
echo $w3->format("Y-m-d\TH:i:s.uP");

Expected result:
(No exception throw!)

Actual result:
PHP Warning:  Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (2016-01-01T01:02:03.123456789-01:02) at position 0 (2): The timezone could not be found in the database' in php shell code:1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-12 06:38 UTC]
-Type: Bug +Type: Feature/Change Request
 [2016-01-12 08:43 UTC] salsi at icosaedro dot it
Might be related to bug #69122 "strtotime and DateTime fail to parse certain strings with fractional seconds".
 [2016-06-14 11:18 UTC] mkroese at eljakim dot nl
Encountered this one today too, while parsing actual timestamps received from another party.

Following paste shows it still works up to 8 digits, and fails at 9 (without a timezone suffix, which makes the error message even more cryptic):

It also shows that the fraction isn't handled correctly with 8 digits (23:59:59.1000000)
 [2020-11-09 11:24 UTC] jan dot espen dot oversand at cerpus dot com
Unfortunately I don't have the resources available to verify with a build of php-src right now.

But, I think, maybe this is related to the max length of 8 at line 1245 of

time->us = timelib_get_frac_nr(&ptr, 8);

Maybe if that was increased to at least 9 (nanosecond) precision. Other systems are doing nanosecond precision and interoperability problems will occur with this limitation.
 [2022-05-20 13:28 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2022-05-20 13:28 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

Both variants of the original comment parse in PHP 8.1, although PHP does not have a high resolution than microseconds:

var_dump(new \DateTime("2016-01-01T01:02:03.123456789-01:02"));
var_dump(new \DateTime("2016-01-01T01:02:03.12345678-01:02"));

Standard input code:2:
class DateTime#1 (3) {
  public $date =>
  string(26) "2016-01-01 01:02:03.123456"
  public $timezone_type =>
  public $timezone =>
  string(6) "-01:02"
Standard input code:3:
class DateTime#1 (3) {
  public $date =>
  string(26) "2016-01-01 01:02:03.123456"
  public $timezone_type =>
  public $timezone =>
  string(6) "-01:02"
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 20:01:31 2024 UTC