How to Get Previous Day, Month, Year From Date In Php

To get previous day, month, year form given date in PHP; Through this tutorial, i am going to show you how to get previous day, month, year from given date in PHP.

How to Get Previous Day, Month, Year From Date In Php

  • How to Get Previous Day From Given Date In Php?
  • How to Get Previous Month From Given Date In Php?
  • How to Get Previous Year From Given Date In Php?

How to Get Previous Day From Given Date In Php?

Using the php date() and strtotime() function, you can get previous day from date in php; let’s see the following example:

<?php
    $date = "2022-01-11";
    $newdate = date("Y-m-d",strtotime ( '-1 day' , strtotime ( $date ) )) ;
    echo $newdate;
?>

Output of the above code; is as follows:

2022-01-10

How to Get Previous Month From Given Date In Php?

Using the php date() and strtotime() function, you can get previous month from date in php; let’s see the following example:

<?php
    $date = "2022-02-11";
    $newdate = date("Y-m-d", strtotime ( '-1 month' , strtotime ( $date ) )) ;
    echo $newdate;
?>

Output of the above code; is as follows:

2022-01-11

How to Get Previous Year From Given Date In Php?

Using the php date() and strtotime() function, you can get previous year from date in php; let’s see the following example:

<?php
    $date = "2022-01-11";
    $newdate = date("Y-m-d",strtotime ( '-1 year' , strtotime ( $date ) )) ;
    echo $newdate;
?>

Output of the above code; is as follows:

2021-01-11

Recommended PHP Tutorials

Leave a Comment