Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return current date plus 7 days

Tags:

date

php

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?

like image 799
James Clear Avatar asked Aug 16 '12 13:08

James Clear


People also ask

How do you add 7 days to a date?

Just do: $date = strtotime("+7 day"); echo date('M d, Y', $date);

How to add 7 days to date in PHP?

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"); ?>

How to get date after 7 days in JavaScript?

const date = new Date(); date. setDate(date. getDate() + 7); console. log(date);

How can I get plus date in PHP?

The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.


1 Answers

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); 
like image 161
Mike Mackintosh Avatar answered Oct 12 '22 22:10

Mike Mackintosh