How to Get Previous Month and Next month date from Date in PHP

AuthorHariom Prajapati

Pubish Date25 Jun 2022

categoryPHP

In this tutorial we will get previous/next month date from current date in PHP and also see how to get previous/next month date form given date in PHP one by one.

 

1) How to get previous month from current date or given date in PHP

Here we will explained get previous month from current date or given date. 

 

a) How to get previous month date from current date in PHP

Simply use below code to get previous month date from current date in php.

<?php
    $PreviousMonthDate = date('Y-m-d', strtotime('-1 month'));
    echo $PreviousMonthDate;
?> 

 

Output:

 

2021-10-16

 

b) How to get previous month date from given date in PHP

Simply use below code to get previous month date from given date in php.

<?php  
    $GivenDate = "2022-02-12";
    $PreviousMonthDate = date('Y-m-d', strtotime($GivenDate. ' -1 months'));
    echo $PreviousMonthDate;
?> 

 

Output:

 

2022-01-12

 

2) How to get next month from current date or given date in PHP

Here we will explained get next month from current date or given date.

 

a) How to get next month date from current date in PHP

Simply use below code to get next month date from current date in php.

<?php
    $NextMonthDate = date('Y-m-d', strtotime('+1 month'));
    echo $NextMonthDate;
?> 

 

Output:

 

2021-12-16

 

b) How to get next month date from given date in PHP

Simply use below code to get next month date from given date in php.

<?php  
    $GivenDate = "2022-02-12";
    $NextMonthDate = date('Y-m-d', strtotime($GivenDate. ' +1 months'));
    echo $NextMonthDate;
?> 

 

Output:

 

2022-03-12

Comments 0

Leave a comment