[php-src] Issue #8275: Function strtotime("-x month", ...) returns different month if the date part is 01-28 or >=29. Additionally different
behaviour for leap and non-leap years

From: Date: Wed, 30 Mar 2022 07:35:10 +0000
Subject: [php-src] Issue #8275: Function strtotime("-x month", ...) returns different month if the date part is 01-28 or >=29. Additionally different
behaviour for leap and non-leap years
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240566@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8275 Comment Author: damianwadley 2022-03-28 minus 1 month is 2022-02-28, which is a perfectly valid date. 2022-03-29 minus 1 month is 2022-02-29, which is not a valid date (this year) and *overflows* to 2022-03-01. In other words, addition and subtraction on dates with PHP behave with the most literal interpretation possible: do the math exactly as told and "fix" the resultant date to be valid. If you want to enforce custom logic during operations, such as "subtract a month but never overflow the result", then you need to do so with code.

« previous php.bugs (#240566) next »