PHP Subtract Days, Month, Year From Date

PHP subtract days, months, and years from date example; In this tutorial, i am going to show you how to subtract days, month,s and years from date in PHP.

PHP Subtract Days, Month, Year From Date

Follow the below given examples to subtract days, months, and year to date from PHP:

  • PHP Subtract Days to Date
  • PHP Subtract Months to Date
  • PHP Subtract Year to Date

PHP Subtract Days to Date

Let’s see the below given example for subtract days to date in php; as follows:

<?php
  
    $date = "2022-01-10";
    $newDate = date('Y-m-d', strtotime($date. ' - 3 days'));
  
    echo $newDate;
  
?>

The output of the above code; as follows:

2022-01-07

PHP Subtract Months to Date

Let’s see the below given example for subtract month to date in php; as follows:

<?php
  
    $date = "2022-05-01";
    $newDate = date('Y-m-d', strtotime($date. ' - 3 months'));
  
    echo $newDate;
  
?>

The output of the above code; as follows:

2022-02-01

PHP Subtract Year to Date

Let’s see the below given example for subtract year to date in php; as follows:

<?php
  
    $date = "2022-02-01";
    $newDate = date('Y-m-d', strtotime($date. ' - 5 years'));
  
    echo $newDate;
  
?>

The output of the above code; as follows:

2017-02-01

Recommended PHP Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.