PHP Subtract Days, Month, Year to Date Tutorial

Through this tutorial, we will show you how to subtract days, months and years to given date in PHP.

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

Here are methods:

  • 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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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