add a day to date, so I can store tomorrow's date in a variable.
$tomor开发者_如何转开发row = date("Y-m-d")+86400;
I forgot.
date
returns a string, whereas you want to be adding 86400 seconds to the timestamp. I think you're looking for this:
$tomorrow = date("Y-m-d", time() + 86400);
I'd encourage you to explore the PHP 5.3 DateTime
class. It makes dates and times far easier to work with:
$tomorrow = new DateTime('tomorrow');
// e.g. echo 2010-10-13
echo $tomorrow->format('d-m-Y');
Furthermore, you can use the + 1 day
syntax with any date:
$xmasDay = new DateTime('2010-12-24 + 1 day');
echo $xmasDay->format('Y-m-d'); // 2010-12-25
date()
returns a string, so adding an integer to it is no good.
First build your tomorrow timestamp, using strtotime
to be not only clean but more accurate (see Pekka's comment):
$tomorrow_timestamp = strtotime("+ 1 day");
Then, use it as the second argument for your date
call:
$tomorrow_date = date("Y-m-d", $tomorrow_timestamp);
Or, if you're in a super-compact mood, that can all be pushed down into
$tomorrow = date("Y-m-d", strtotime("+ 1 day"));
Nice and obvious:
$tomorrow = strtotime('tomorrow');
You can use the add
method datetime
class.
Eg, you want to add one day to current date and time.
$today = new DateTime();
$today->add(new DateInterval('P1D'));
Further reference php datetime add
Hope this helps.
I find mktime()
most useful for this sort of thing. E.g.:
$tomorrow=date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")+1, date("Y")));
精彩评论