How to add days to date using PHP

3 comments
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
$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');

and the second method is:
$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.

3 comments :

  1. This is a very amazing post for cheap web hosting services. in this post, you have provided all the basic information regarding.

    white label website builder

    ReplyDelete
  2. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    private label website builder

    ReplyDelete
  3. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    website builder for reseller

    ReplyDelete