作成日:2018-01-31, 更新日:2018-06-24
基本
「strtotime()」自体がよろしくないとか・・・そういうのはとりあえず置いておく。
▼NG例
echo date('m月', strtotime('-1 month'));
▼OK例
echo date('m月', strtotime(date('Y-m-01') . ' -1 month'));
・NG例は今日の1ヵ月前
・OK例は今月の1日の1ヵ月前
今日の1ヵ月前の場合、「今日が31日、前月が30日までしかない」とき前月じゃなくて今月が表示される
前月が30日などのときの例
echo date('m月', strtotime(date('2018-05-31') . ' -1 month')); // 5月 echo date('m月', strtotime(date('2018-05-01') . ' -1 month')); // 4月