Unable to understand DateTime class behavior in PHP

I am using LAMP in Kubuntu 14.04 with PHP 5.6.23.

When using DateTime in the following cases:

1.

print_r((new DateTime('2016-02-31'))->format('M/d/Y')); 
// Mar/02/2016 (no errors, why?)

2.

print_r((new DateTime('2016-02-32'))->format('M/d/Y')); 
// Error - DateTime::__construct(): Failed to parse time string-
// (2016-02-32) at position 9 (2): Unexpected character

Why does the first case not give me any error, since the 31st date of the month of February is missing?

Links Supported Response Requested

+4
source share
1 answer

From php docs:

Possible overflow and invalid format dd and DD. Day 0 means the last day of the previous month, while overflow is considered in the next month. This means that “2008-08-00” is equivalent to “2008-07-31” and “2008-06-31” is equivalent to “2008-07-01” (in June there are only 30 days).

, PHP 5.1.0 0-31, . , "2008-06-32" , .

.

Mirek mktime, :

unlimited over/underflow (, 2015-01-40 2015-02-09)

+7

Source: https://habr.com/ru/post/1663324/


All Articles