PHP subtract 1 month from date formatted with date ('m-Y')

后端 未结 10 648
北恋
北恋 2020-12-20 11:11

I\'m trying to subtract 1 month from a date.

$today = date(\'m-Y\');

This gives: 08-2016

How can I subtract a month to get 07

10条回答
  •  佛祖请我去吃肉
    2020-12-20 11:29

    $currentMonth = date('m', time());
    $currentDay = date('d',time());
    $currentYear = date('Y',time());
    $lastMonth = $currentMonth -1;
    $one_month_ago=mkdate(0,0,0,$one_month_ago,$currentDay,$currentYear);
    

    This could be rewritten more elegantly, but it works for me

提交回复
热议问题