tags:

views:

4621

answers:

4
+4  A: 

a day is 86400 seconds.

$tomorrow = date('y:m:d', time() + 86400);
nickf
Although, for readability reasons you shoudn't use the Integer everywhere as-is. define a const somewhere or use 60 * 60 * 24 so its clear what the number represents.
Kent Fredric
i use 86400 so often that it's as obvious to me now as it is that there's 60 seconds in a minute :). If I am doing a lot of time functions, then yes, I'll often declare it a constant.
nickf
+2  A: 

The date_add() function should do what you want. In addition, check out the docs (unofficial, but the official ones are a bit sparse) for the DateTime object, it's much nicer to work with than the procedural functions in PHP.

eplawless
+5  A: 

php supports c style date functions. You can add or substract date-periods with english-language style phrases via the strtotime function. examples...

$Today=date('y:m:d');

// add 3 days to date
$NewDate=Date('y:m:d', strtotime("+3 days"));

// subtract 3 days from date
$NewDate=Date('y:m:d', strtotime("-3 days"));

// PHP returns last sunday's date
$NewDate=Date('y:m:d', strtotime("Last Sunday"));

// One week from last sunday
$NewDate=Date('y:m:d', strtotime("+7 days Last Sunday"));
using the strtotime() function is very expensive and would be massive overkill if you just want to add a couple of days.
nickf
Sounds like premature optimization. If it's not in a time-critical piece of code, and we have no reason to think it is, burning a few milliseconds is nothing compared to the cost of programmer time.
Andy Lester
A: 

e.g. to get tomorrow:

sleep(24*60*60);
$tomorrow = time();

:)