Getting last month's date in php

前端 未结 18 738
心在旅途
心在旅途 2020-11-29 00:22

I want to get last month\'s date. I wrote this out:

$prevmonth = date(\'M Y\');

Which gives me the current month/year. I can\'t tell if I

18条回答
  •  情深已故
    2020-11-29 00:32

    Found this one wrong when the previous months is shorter than current.

    echo date("Y-m-d H:i:s",strtotime("-1 month"));
    

    Try on March the 30th and you will get 2012-03-01 instead of 2012-02...

    Working out on better solution...

提交回复
热议问题