Req #78766 [NEW]: date('Y-m-d', '-1 month') don't work as expected n day 31

From: Date: Thu, 31 Oct 2019 14:39:56 +0000
Subject: Req #78766 [NEW]: date('Y-m-d', '-1 month') don't work as expected n day 31
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223537@lists.php.net to get a copy of this message
From: gabrielklasso at gmail dot com Operating system: Any PHP version: Irrelevant Package: Date/time related Bug Type: Feature/Change Request Bug description:date('Y-m-d', '-1 month') don't work as expected n day 31 Description: ------------ When I run date('m', '-1 month'), I expect to get the number of the previous month, but it is not what always happen. Today is 2019-10-31, and when I run it I got '10'. To understand better what is happening, I tried to run date('Y-m-d', '-1 month') and I got '2019-10-01'. I believe it is because there is no day 2019-09-31, so it rounds up. But IMO it should round down in this case. Test script: --------------- $lastMonth = date('m', '-1 month'); echo $lastMonth; Expected result: ---------------- '9' Actual result: -------------- '10' -- Edit bug report at https://bugs.php.net/bug.php?id=78766&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=78766&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78766&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78766&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78766&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78766&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78766&r=support Expected behavior: https://bugs.php.net/fix.php?id=78766&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78766&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78766&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78766&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=78766&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=78766&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78766&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78766&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78766&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78766&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78766&r=mysqlcfg

« previous php.bugs (#223537) next »