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').
You can use the date() and strtotime() functions in PHP to subtract one month from a date formatted with date('m-Y'). Here is an example:
Example of using PHP date function to subtract one month from a date formatted with date('m-Y')
php— editable, runs on the server
Info
Watch a video course: Learn object oriented PHP
This will output 05-2023 and 04-2023. The strtotime() function parses the relative time string "-1 month" against the base date, and the date() function formats the resulting timestamp into the m-Y format.