get previous month in php – How to Get Previous Month from Date in PHP?

0
()

get previous month in php and display it. The PHP date function is used to format a date. here we can learn to main 2 Examples.

get previous month in php

Get Previous Month to $Date can be done in many ways. The following source code will get previous months in php to date.

Example 1: PHP Get Previous Month from Current Date

php_get_previous_month_from_current_date.php

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

Result

2022-10-15

don’t miss : Get Next Month In Php

Read Also:  php array remove empty - How to remove empty values from an array in PHP?

Example 2: PHP Get Previous Month from Given Date

php_get_previous_month_from_given_date.php

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

Result

2022-01-01

Download

I hope you get an idea about get previous month in php.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  how to check if a file exists in php?

How useful was this post?

Free Live Chat for Any Issue

Click on a star to rate it!