php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71865 strtotime treat as valid date
Submitted: 2016-03-21 07:13 UTC Modified: 2016-03-22 11:31 UTC
From: finull at vip dot qq dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.19 OS: MacOS X 10.11
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: finull at vip dot qq dot com
New email:
PHP Version: OS:

 

 [2016-03-21 07:13 UTC] finull at vip dot qq dot com
Description:
------------
Found this bug when I use strtotime to checkout if input was valid date. 

strtotime(1458533078) should return FALSE, but it does't;


Test script:
---------------
$timestamp = strtotime(1458533078);
// output: 34971980333
echo $timestamp;




Expected result:
----------------
FALSE

Actual result:
--------------
34971980333

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-21 07:26 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-03-21 07:26 UTC] requinix@php.net
You've discovered the HHMMSSYYYY format.
 [2016-03-22 03:23 UTC] finull at vip dot qq dot com
I also got this output

strtotime(1458363078) returns FALSE
strtotime(1458373078) returns 34972066717

Why?
 [2016-03-22 03:38 UTC] requinix@php.net
https://3v4l.org/TM23M

1458363078 is parsed as 1458=year, 363=day, then invalid characters (PostgreSQL compound format)
1458373078 is parsed as 14=hour, 58=minute, 37=second, year=3078 (time and date formats)

Don't pass Unix timestamps to strtotime.
 [2016-03-22 03:45 UTC] finull at vip dot qq dot com
got it.

Thanks a lot!
 [2016-03-22 11:31 UTC] derick@php.net
As a hint, if you get weird results, use date_parse, and it will tell you how it (tried to) parse the string:

derick@whisky:~ $ php -r 'var_dump(date_parse("1458363078"));'
Command line code:1:
array(12) {
  'year' =>
  int(1458)
  'month' =>
  int(1)
  'day' =>
  int(363)
  'hour' =>
  bool(false)
  'minute' =>
  bool(false)
  'second' =>
  bool(false)
  'fraction' =>
  bool(false)
  'warning_count' =>
  int(1)
  'warnings' =>
  array(1) {
    [11] =>
    string(27) "The parsed date was invalid"
  }
  'error_count' =>
  int(3)
  'errors' =>
  array(3) {
    [7] =>
    string(20) "Unexpected character"
    [8] =>
    string(20) "Unexpected character"
    [9] =>
    string(20) "Unexpected character"
  }
  'is_localtime' =>
  bool(false)
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 19:01:32 2024 UTC