How to Add Days to Date in PHP Examples

Last Updated on July 28, 2022 by Roshan Parihar

In this tutorial, learn how to add days to date using PHP. The short answer is to use the strtotime() function of PHP and pass the date with addition of number of days.

You can also add variable days to add the your required date. Both the data and the number of days can be a variable in PHP. You can use these variables to add days to date in PHP.

Let’s see some example that can makes it easier to learn the method.

How to Add Days to Date in PHP

If you want to add days to date in PHP, you can use the strtotime() function. There are two elements you have to pass to the function. The first element is the number of days and the second is the number of days to add the date. See the below example to learn the method.

Output

2022-08-11

The above example contains a variable $date that stores the dates. After that, it uses the strtotime() function to add 15 days to the specified data. The output shows that 15 days is added to the specified data in PHP.

PHP Use Variables for Adding Days

In addition to the above example, you can also make the number days as a variable to add to the specified dates in PHP. To do this, you have to use the method as given in the example below.

Output

2022-08-11

If you want to increase the number of day dynamically to the specified dates in PHP, you can use the above example. When you want to find out different dates after adding different number of day, the above methods can be useful for you.

The dynamic addition can be done using the variables in the function in PHP. It can make adding dynamic dates easier in the output.

You May Also Like to Read

I hope you like this post on increase the dates by adding the numbers to it.

Reference: Stackoverflow

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.