|  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
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 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: 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
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


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

Expected result:
 [2004-11-15 18:58 UTC]
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: Sun Jul 21 08:01:28 2024 UTC