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
Warning! The above-mentioned examples won't work if call them at the end of a month.
will output:
10-2017
10-2017
The following example will produce the same result:
$date = new DateTime('2017-10-31 00:00:00');
echo $date->format('m-Y')."\n";
$date->modify('-1 month');
echo $date->format('m-Y')."\n";
Plenty of ways how to solve the issue can be found in another thread: PHP DateTime::modify adding and subtracting months