I'm Trying to get the current date plus 7 days to display.
Example: Today is August 16, 2012, so this php snippet would output August 23, 2012.
$date = strtotime($date); $date = strtotime("+7 day", $date); echo date('M d, Y', $date);
Right now, I'm getting: Jan 08, 1970. What am I missing?
Just do: $date = strtotime("+7 day"); echo date('M d, Y', $date);
php $date = date_create("2019-11-11"); echo "Displaying Date..."; echo date_format($date,"Y/m/d"); date_add($date, date_interval_create_from_date_string("25 days")); echo "\nDisplaying Updated Date..."; echo "\n". date_format($date, "Y/m/d"); ?>
const date = new Date(); date. setDate(date. getDate() + 7); console. log(date);
The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.
strtotime
will automatically use the current unix timestamp to base your string annotation off of.
Just do:
$date = strtotime("+7 day"); echo date('M d, Y', $date);
Added Info For Future Visitors: If you need to pass a timestamp to the function, the below will work.
This will calculate 7 days
from yesterday:
$timestamp = time()-86400; $date = strtotime("+7 day", $timestamp); echo date('M d, Y', $date);
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