php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30190 strtotime doesn't return -1 from 0000-00-00
Submitted: 2004-09-22 03:18 UTC Modified: 2004-11-15 20:17 UTC
Votes:12
Avg. Score:4.7 ± 0.6
Reproduced:12 of 12 (100.0%)
Same Version:3 (25.0%)
Same OS:4 (33.3%)
From: mike dot deeks at equest dot com Assigned: derick (profile)
Status: Wont fix Package: Date/time related
PHP Version: 4.3.8 OS: Debian, Linux
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: mike dot deeks at equest dot com
New email:
PHP Version: OS:

 

 [2004-09-22 03:18 UTC] mike dot deeks at equest dot com
Description:
------------
strtotime returns the date 1999-11-31 (Timestamp: 943948800) instead of -1 when I pass it "0000-00-00".

From what I can tell, it assumes 0000 is the year 2000. Then the 00 month and 00 day refer to the previous month and the previous day from the year 2000. i.e. "2000-01-01" minus one month, and one day.

Should it not return a -1 because that is an invalid time?

"0000-00-00" is what MySQL defaults invalid DATE values to by the way.

Reproduce code:
---------------
echo strtotime("2000-01-01") . "/n";
echo strtotime("2000-01-00") . "/n";
echo strtotime("2000-00-00") . "/n";
echo strtotime("0000-00-00") . "/n";

Expected result:
----------------
946713600
946627200
-1
-1

Actual result:
--------------
946713600
946627200
943948800
943948800

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-22 03:24 UTC] mike dot deeks at equest dot com
Correction. Expected Results should read:

Expected result:
----------------
946713600
946627200
943948800
-1
 [2004-11-15 18:58 UTC] derick@php.net
The parser in PHP 4 does not distinguish between "0" , "00", "000" or "0000" and this can not be solved easily. The new parser for PHP 5 will be able to handle the year 0 correctly as an error.
 [2004-11-15 20:17 UTC] mike dot deeks at equest dot com
Ok, I understand. It is easy enough to work around anyway.

Thanks for taking a look.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC