Today in this tutorial, we will see how to add or subtract days, month, and year from date using PHP. This is a very simple and very short point-to-point tutorial.
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.
So let’s see some examples.
Add Days, Month, and Year to Date in PHP
In this case, we will see how to add days, months, and years to the current date or any date. We will use built-in functions like date() and strtotime(). See the following examples.
Add +3 days to date
Add +7 days to date
Add +1 month to date
Add +1 year to date
Add days to current date
As see the above example to add the days to date in given date, same we can do with the current date. We just have to go with only the date() function and remove the given date variable. See the following reference.
Subtract Days, Month, and Year from Date in PHP
Now, we will see how to subtract days, months, and years to the current date or any date. We will use the same built-in functions like the date() and strtotime(). See the following examples. Only we just have to subtract instead of add.
Subtract -3 days from date
Subtract -7 days from date
Subtract -1 month from date
Subtract -1 year from date
Subtract days from current date
As you see all the above examples, it is very easy to add or subtract days, month, and year from date using PHP core functions.