W3docs

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

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

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.