Return current date plus 7 days
PhpDatePhp Problem Overview
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?
Php Solutions
Solution 1 - Php
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);
Solution 2 - Php
$date = new DateTime(date("Y-m-d"));
$date->modify('+7 day');
$tomorrowDATE = $date->format('Y-m-d');
Solution 3 - Php
If it's 7 days from now that you're looking for, just put:
$date = strtotime("+7 day", time());
echo date('M d, Y', $date);
Solution 4 - Php
$now = date('Y-m-d');
$start_date = strtotime($now);
$end_date = strtotime("+7 day", $start_date);
echo date('Y-m-d', $start_date) . ' + 7 days = ' . date('Y-m-d', $end_date);
Solution 5 - Php
<?php
print date('M d, Y', strtotime('+7 days') );
Solution 6 - Php
you didn't use time() function that returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). use like this:
$date = strtotime(time());
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);
Solution 7 - Php
This code works for me:
<?php
$date = "21.12.2015";
$newDate = date("d.m.Y",strtotime($date."+2 day"));
echo $newDate; // print 23.12.2015
?>
Solution 8 - Php
echo date('d-m-Y', strtotime('+7 days'));
Solution 9 - Php
$date = strtotime("+7 day", strtotime("M d, Y"));
$date = date('j M, Y', $date);
This will work as well
Solution 10 - Php
Here is how you can do it using strtotime()
,
<?php
$date = strtotime("3 October 2005");
$d = strtotime("+7 day", $date);
echo "Created date is " . date("Y-m-d h:i:sa", $d) . "<br>";
?>