How to Subtract Days, Month, Year to Date in PHP?
Jan 17, 2023
Hi Dev,
This tutorial is focused on how to subtract days, months, and years to date in PHP. you'll learn how to subtract days to date in PHP. We will use how to subtract months to date in PHP. if you have a question about how to subtract years to date in PHP then I will give a simple example with a solution.
Now, let's see the article on how to subtract days, months, and years to date using PHP. it's a simple example of how to subtract days to date in PHP. you can understand the concept of how to subtract months to date in PHP. if you have a question about how to subtract years to date in PHP then I will give a simple example with a solution.
Example 1: PHP Subtract Days to Date
<?php
$date = "2022-01-10";
$newDate = date('Y-m-d', strtotime($date. ' - 3 days'));
print_r($newDate);
?>
Output:
2022-01-07
Example 2: PHP Subtract Months to Date
<?php
$date = "2022-05-01";
$newDate = date('Y-m-d', strtotime($date. ' - 3 months'));
print_r($newDate);
?>
Output:
2022-02-01
Example 3: PHP Subtract Year to Date
<?php
$date = "2022-02-01";
$newDate = date('Y-m-d', strtotime($date. ' - 5 years'));
print_r($newDate);
?>
Output:
2017-02-01
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example