Return current date plus 7 days

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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?

回答1:

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


回答2:

$date = new DateTime(date("Y-m-d")); $date->modify('+7 day'); $tomorrowDATE = $date->format('Y-m-d');


回答3:

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


回答4:

<?php print date('M d, Y', strtotime('+7 days') );


回答5:

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


回答6:

$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);


回答7:

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 ?>


转载请标明出处:Return current date plus 7 days
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!