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

You can use the DateTime object in PHP to subtract one month from a date formatted with date('m-Y'). Here is an example:

<?php

$date = date('Y-m-d');
$prev_month = date('m-Y', strtotime("-1 month", strtotime($date)));

echo "Current month: " . date('m-Y') . "\n";
echo "Previous month: " . $prev_month . "\n";

Watch a course Learn object oriented PHP

This will output "12-2021". The DateInterval object is used to specify the interval of time to subtract, in this case "P1M" for one month. The format method is then used to output the date in the desired format of "m-Y".