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

Menu