PHP strtotime +1 month behaviour

前端 未结 8 2201
再見小時候
再見小時候 2020-11-30 10:10

I know about the unwanted behaviour of PHP\'s function

strtotime

For example, when adding a month (+1

8条回答
  •  盖世英雄少女心
    2020-11-30 10:49

    Here's the algorithm you can use. It should be simple enough to implement yourself.

    • Have the original date and the +1 month date in variables
    • Extract the month part of both variables
    • If the difference is greater than 1 month (or if the original is December and the other is not January) change the latter variable to the last day of the next month. You can use for example t in date() to get the last day: date( 't.m.Y' )

提交回复
热议问题