php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69122 strtotime and DateTime fail to parse certain strings with fractional seconds
Submitted: 2015-02-26 00:50 UTC Modified: 2022-05-13 14:44 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: alexander dot minges at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.6.6 OS: Linux 3.18.7 x86_64 GNU/Lin
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander dot minges at gmail dot com
New email:
PHP Version: OS:

 

 [2015-02-26 00:50 UTC] alexander dot minges at gmail dot com
Description:
------------
strtotime fails to parse strings in the format "Feb 25 23:38:22.226 2015 GMT" while "Feb 25 23:38:22 2015 GMT" is parsed fine. The same applies to creating a DateTime object.

Test script:
---------------
<?php
    //This works
    echo strtotime("Feb 25 23:38:22 2015 GMT");
    //This one does not
    echo strtotime("Feb 25 23:38:22.226 2015 GMT");
?>

Expected result:
----------------
1424907502
1424907502

Actual result:
--------------
1424907502

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-26 01:03 UTC] requinix@php.net
-Type: Bug +Type: Feature/Change Request
 [2015-02-26 01:03 UTC] requinix@php.net
The most it could do is ignore the microseconds.

Meanwhile
  DateTime::createFromFormat("M d H:i:s.u Y T", "Feb 25 23:38:22.226 2015 GMT")
works fine.
 [2015-09-27 09:59 UTC] salsi at icosaedro dot it
I run into this issue just today, trying to parse ODS files with PHPExcel, where some properties contain a timestamp with many fractional digits. Apparently strtotime() always returns false if there are more than 7 decimals. For example:

var_dump(strtotime("1970-01-02 00:00:00.000 GMT"));
// int(86400), ok

var_dump(strtotime("1970-01-02 00:00:00.00000000 GMT"));
// expected: int(86400), got: bool(false)
 [2022-05-13 14:44 UTC] derick@php.net
-Status: Open +Status: Wont fix
 [2022-05-13 14:44 UTC] derick@php.net
I am going to have to close this one, as it would cause ambiguities in the parser. Unfortunately, we can't make the parser smart enough to understand *every format* that you throw at it without making it mega complex.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC