How to add days to date using PHP
Last Modified at 2019-06-30 17:21:15
Whether, you are printing a future date or you are creating a report in which, you need to create a weekly report or a monthly report and you want to add n number of days in current date to create your desired report then in such conditions this blog is useful for you.
So lets start with the ways, we can add days into date by using PHP language. There couple of ways, first one is, If you are using PHP 5.3 or greter version then you can add days to date with DateInterval() function. And if you are using lower version than PHP 5.3 then you should use PHP inbuilt function date() and date() function also works in latest PHP versions.PHP 5.3
and the second method is:
$Date1 = '2019-04-10';
$date = new DateTime($Date1);
$date->add(new DateInterval('P1D')); // Here P1D means a period of 1 day
$Date2 = $date->format('Y-m-d');
$Date = date('Y-m-d', strtotime("2019-04-10" . " + 1 day")); // Here +1 is used for adding 1 day into date. If you add -1 instead of +1 it will print 09-04-2019
Hope you will like this blog. Please let me know, your comments below.