Friday, November 21, 2025
HomeLanguagesPHP Subtract Days, Month, Year to Date

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.

How to Subtract Days, Month, Year to Date in PHP

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-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

Use the following php code to subtract month to date; 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

Use the following php code to subtract year to date; 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

RELATED ARTICLES

Most Popular

Dominic
32406 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6783 POSTS0 COMMENTS
Nicole Veronica
11929 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7167 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS