today 22-05-2011 so it should be 29-05-2011? ( plus 1 week )
or
today 22-05-2011 so it should be 15-05-2011? ( minus 1 week )
thanks for looking in.
Adam Ramadhan
Just do: $date = strtotime("+7 day"); echo date('M d, Y', $date);
just used it - date('Y-m-d H:i:s', strtotime('+1 week')); works fine in PHP 7 to give one week from now.
Answer: Use the strtotime() Function You can first use the PHP strtotime() function to convert any textual datetime into Unix timestamp, then simply use the PHP date() function to convert this timestamp into desired date format. The following example will convert a date from yyyy-mm-dd format to dd-mm-yyyy.
Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds. Syntax: date_add(object, interval);
Use strtotime()
echo date('d-m-Y', strtotime("+1 week")); //1 week in the future
echo date('d-m-Y', strtotime("-1 week")); //1 week ago
You can use the DateTime
class to do calendar calculations. For exaple, to add one week, you could use code like this:
$date = new DateTime('22-05-2011');
$date->modify('+1 week');
strtotime will handle this.
$pDate = strtotime('22-05-2011 + 1 week');
echo date('d-m-Y',$pDate);
Added: This is if you want to start from a specific date. If you just want 'today' +/- a week', mark JohnP's answer as correct. : )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With