PHP Subtract Days, Month, Year to Date

Subtract days, months, and years to date in PHP; Through this tutorial, we will learn how to subtract days, month,s and years to date in PHP.

You will see how you can add or subtract 1 day, 5 days, 1 month, or even 1 year from any date. You can also add or subtract days from the current date using these tutorial references.

Use the following example to subtract days, months, and year to date in PHP; as follows:

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

PHP Subtract Days to Date

Use the following PHP code to subtract days to date; as follows:

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

The output of the above code; as follows:

2022-04-07

PHP Subtract Months to Date

Use the following php code to subtract month to date; as follows:

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

The output of the above code; as follows:

2022-03-16

PHP Subtract Year to Date

Use the following php code to subtract year to date; as follows:

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

The output of the above code; as follows:

2017-04-16

Leave a Reply

Your email address will not be published.