Yasen Zhelev
Yasen Zhelev

Reputation: 4045

New way of defining timestamp in PHP 5.3?

Is there a new approach in PHP 5.3 to define timestamp?

this strtotime('0000-00-00');

will return 0 date(01/01/1970) in PHP prior 5.3 and -62169984000 in PHP 5.3. And a date like 30/11/-0001 !!

But I could not find any explanations about that in the documentation. Any idea was that changed or I am missing something?

Upvotes: 3

Views: 948

Answers (1)

Naftali
Naftali

Reputation: 146310

Explanation is here: https://bugs.php.net/bug.php?id=46597

To Quote:

Sure, but strtotime() has long handled invalid month and day values the same way as mktime() by effectively "rounding" them into valid values: the 0th day of the month becomes the last day of the previous month, the 0th month is the last month of the previous year, and so on. Given that interpretation, 0000-00-00 fairly obviously becomes the last day of November in the year -1 (better known as 2 BCE).

There's no chance that behaviour is going to be changed now: checkdate() is a much better way of sniffing out invalid dates anyway, and it would be a potentially nasty backward compatibility break for people relying on this behaviour in strtotime().

Upvotes: 5

Related Questions