PHP Strtotime -1month -2month

前端 未结 6 572
感情败类
感情败类 2020-12-06 06:00

This was working fine yesterday with no changes to the code.

echo date(\"M\", strtotime(\"-3 month\", time()) );
echo date(\"M\", strtotime(\"-2 month\", tim         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 06:32

    Try this instead of strtotime:

    mktime(0, (date("n") - 3 + 12) % 12, 1)
    

    The idea is to take the current month number (date("n")), substract the number of months from it you want (here -3), add 12 to it and then get modulo 12.

提交回复
热议问题