Home » Php » datetime – php – add + 7 days to date format mm dd, YYYY

datetime – php – add + 7 days to date format mm dd, YYYY

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have date of this format March 3, 2011 in database and I need to extend it with 7 days. I mean

 $date = $date + 7

. Is there any build in function to do that ?

How to&Answers:
$date = "Mar 03, 2011";
$date = strtotime($date);
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);

Answer:

The “+1 month” issue with strtotime

As noted in several blogs, strtotime() solves the “+1 month” (“next month”) issue on days that do not exist in the subsequent month differently than other implementations like for example MySQL.

$dt = date("Y-m-d");
echo date( "Y-m-d", strtotime( "$dt +1 day" ) ); // PHP:  2009-03-04
echo date( "Y-m-d", strtotime( "2009-01-31 +2 month" ) ); // PHP:  2009-03-31

Answer:

Another more recent and object style way to do it :

$date = new DateTime('now');
$date->add(new DateInterval('P7D'));

php doc of datetime add

Answer:

echo date('d/m/Y', strtotime('+7 days'));

Answer:

yes

$oneweekfromnow = strtotime("+1 week", strtotime("<date-from-db>"));

on another note, why do you have your date in the database like that?

Answer:

onClose: function(selectedDate) {

    $("#dpTodate").datepicker("option", "minDate", selectedDate);
    var maxDate = new Date(selectedDate);

     maxDate.setDate(maxDate.getDate() + 6); //6 days extra in from date

     $("#dpTodate").datepicker("option", "maxDate", maxDate);
}