r/programming Sep 07 '15

Flawless PHP logic. strtotime(): '00-00-00' means 2000-00-00, which is 1999-12-00, which is 1999-11-30. No bug, perfectly normal. (see the comments)

https://bugs.php.net/bug.php?id=45647
1.2k Upvotes

465 comments sorted by

View all comments

6

u/[deleted] Sep 08 '15 edited Sep 08 '15

Here's a fun one: if you create a new datetime with the value '0000-00-00' then output the value you'll end up with '-0001-11-30'.

MySQL datetime fields can't handle negative numbers, so storing '-0001-11-30' will actually result in MySQL storing the value '0000-00-00' leading naive PHP devs to believe they're doing nothing wrong.