How to Get Previous Month from Date in PHP?
This is a short guide on how to get previous month date in php. Here you will learn php get previous month from given date. i explained simply step by step php get previous month from current date. We will look at example of how to get previous month date in php. So, let's follow few step to create example of how to get previous month in php example.
I will give you very simple example how to previous month date in PHP. so let's see both example with output:
Example 1: PHP Get Previous Month from Current Date
index.php
<?php
$newDate = date('Y-m-d', strtotime('-1 month'));
echo $newDate;
?>
Output:
2021-10-15
Example 2: PHP Get Previous Month from Given Date
index.php
<?php
$date = "2021-02-01";
$newDate = date('Y-m-d', strtotime($date. ' -1 months'));
echo $newDate;
?>
Output:
2021-01-01
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Tomorrow Date in PHP?
- How to Get Yesterday Date in PHP?
- PHP Subtract Seconds from Time Example
- How to Subtract Minutes from DateTime in PHP?
- How to Subtract Hours from DateTime in PHP?
- How to Add Seconds to Time in PHP?
- PHP Add Minutes to Time Example
- PHP Add Hours to Datetime Example
- PHP Subtract Year from Date Example