Date function, why the December 31st minus one month is December 1st

echo date("Y-m-d", strtotime("last month", strtotime("2018-12-31"))) 

this output 12-01

Mar.29,2022

Internal processing logic:

  1. do-1 month first, so the current number is 07-31, which is 06-31 after subtracting one.
  2. normalize the date again, because June does not have 31, so it is as if 2: 60 equals 3: 00, and June 31 equals July 1

Brother Bird made it very clear: http://www.laruence.com/2018/...


as mentioned above, this problem is due to the overflow of the date after rigid subtraction. So I added it directly to next month. The same problem occurs many times in the user's notes under the official documentation strtotime method, but few provide solutions, so turn to one of them.

attached by the way Obtaining the next month in PHP

  

because there is no November 31

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e6eb28-1fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e6eb28-1fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?