php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74930 when $timestamp > 1500367000, strtotime($timestamp) won't return false
Submitted: 2017-07-15 17:29 UTC Modified: 2017-07-19 07:16 UTC
From: yaozeyuan93 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.31 OS: Any
Private report: No CVE-ID: None
 [2017-07-15 17:29 UTC] yaozeyuan93 at gmail dot com
Description:
------------
according to [document](http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-changelog), put number into strtotime will be ignore and return false. But if the number > 1500367000, strtotime will return a big number but not false instead

Test script:
---------------
<?php

$timestamp = 1500367000; // result by strtotime('2017-7-18 16:36:40'),larger will also had this problem
echo strtotime($timestamp); // while return 158748447636, not false

Actual result:
--------------
158748447636

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-15 17:36 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-07-15 17:36 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Because that number looks like HHMMSSYYYY format.
http://php.net/manual/en/datetime.formats.php

strtotime has to assume that what you pass is supposed to be a date/time string of some sorts. Garbage in, garbage out.
 [2017-07-19 01:54 UTC] johnoflah at gmail dot com
If it is looking for HHMMSSYYYY why would:

strtotime("1500366999");

return false but:

strtotime("1500367000");

return a timestamp?
 [2017-07-19 06:27 UTC] requinix@php.net
Because 1500366999 looks like it fits the format YYYYdoy (year 1500, day of year 366) but is rejected due to the extra characters '999' at the end.

https://3v4l.org/MsDGL

I'll say it again: garbage in, garbage out. If strtotime has to try to make sense of something that is not a date string then you may get unexpected results.
 [2017-07-19 07:16 UTC] derick@php.net
And you can make it work by prefixing the @ in front of the number:

strtotime("@1500367000");
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC