Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 414
Yasen Zhelev Avatar asked Nov 27 '25 09:11

Yasen Zhelev


1 Answers

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().

like image 131
Naftali Avatar answered Nov 28 '25 23:11

Naftali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!