tags:

views:

39

answers:

4

add a day to date, so I can store tomorrow's date in a variable.

$tomorrow = date("Y-m-d")+86400;

I forgot.

+2  A: 

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"));
Matchu
+1 but a nicer way to build the timestamp would be `strtotime("+ 1 day");` because of DST
Pekka
@Pekka: neat! Edited :)
Matchu
+1  A: 

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);
casablanca
What about DST?
Pekka
Indeed, this will fail due to daylight saving. You should never write arithmetic like this.
David Caunt
Agreed that this fails to account for DST. I just answered based on whatever OP was trying to do, whether or not that's really what he wants is up to him to decide.
casablanca
+3  A: 

Nice and obvious:

$tomorrow = strtotime('tomorrow');
David Caunt
Neat, but, in its current form, doesn't seem to match the OP's requirements :/ Add in that `date` call and we're good to go.
Matchu
+3  A: 

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
lonesomeday
+1 for `DateTime`, it's the future.
Pekka
@Pekka Agreed - very good api
David Caunt