|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45550 BC break: strtotime parses 0000-00-00 00:00:00 as valid date in 5.2.6
Submitted: 2008-07-17 22:00 UTC Modified: 2008-07-18 13:31 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: jack+phpdotnet at smartertravelmedia dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.6 OS: RHEL 4/5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: jack+phpdotnet at smartertravelmedia dot com
New email:
PHP Version: OS:


 [2008-07-17 22:00 UTC] jack+phpdotnet at smartertravelmedia dot com
MySQL uses '0000-00-00 00:00:00' as a default value for non-null datetime fields.  Until 5.2.6, strtotime correctly returned false (or -1 before 5.1) when passed this value - it's not a valid date/time.

5.2.6 returns '-62169966000' which is not useful.

Reproduce code:
<?php echo (int)strtotime('0000-00-00 00:00:00');

Expected result:
Should print 0.

Actual result:
Actually prints -62169966000.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-18 02:32 UTC] jack+phpdotnet at smartertravelmedia dot com
updated subject to note that this is a backward-compatibility break.
 [2008-07-18 07:25 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

This is not a bug. MySQL is being silly to use this string as a default value. In PHP 5.3 you can now detect this however, by using date_parse_from_format( "Y-m-d H:i:s"); and then check the contents of date_get_last_errors().
 [2008-07-18 13:31 UTC] jack+phpdotnet at smartertravelmedia dot com
First of all, those previously-reported bugs are with the DateTime class, not strtotime.  If DateTime uses strtotime or its underlying implementation, that's not for me to know.  I searched the bug database before submitting this report and did not find the two you mentioned.  Your "similar bugs" prompt didn't flag them either.

Second, how is this not a bug?  strtotime's manual page says, "Returns a timestamp on success, FALSE otherwise."  The string of zeroes that mysql uses is NOT a valid datetime string, so how is strtotime "successfully" parsing it into a random negative number?  That's aside from the fact that this is a behavior *change* from 5.2.5 to 5.2.6 - that alone makes it a problem.

Third, you can think mysql is silly for using this as a default all you want, but they've been doing it since at least version 3.23 if not before.  Just because you don't agree with it doesn't mean PHP shouldn't handle it as advertised - namely to return false if an invalid date/time string is passed to strtotime.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 12 17:01:33 2024 UTC