How to Get Next, Previous Day, Month And Year From Date In PHP

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

Use following examples for get next, previous day, month, year from given data in php; is as follows:

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

How to Get Previous Day From Date In Php?

You can see the following example of how to get previous day from date in php:

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

Output:

2022-02-11

How to Get Next Day From Date In Php?

You can see the following example of how to get next day from date in php:

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

output:

2022-02-11

How to Get Previous Month From Date In Php?

This example of how to get previous month from date in php:

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

OutPut:

2021-01-11

How to Get Next Month From Date In Php?

You can see the following example of how to get next month from date in php:

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

Output:

2022-03-11

How to Get Previous Year From Date In Php?

For find previous year from date in PHP, So, You can see the following example:

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

OutPut:

2021-02-11


How to Get Next Year From Date In Php?

For find next year from date in PHP, So, You can see the following example:

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

Output:

2023-02-11

Leave a Reply

Your email address will not be published. Required fields are marked *