tags:

views:

134

answers:

6

Would it be possible to get the unix timestamp 7 days from now?

Would be awesome!

+4  A: 

Yes, get the unix timestamp and add 25200 to it. If you want to format that timestamp you can use date().

$future = time() + (60 * 60 * 24 * 7);
date("o", future);

And from the PHP docs for time()

date('Y-m-d', strtotime('+1 week'))
infamouse
Missing a multiplier O.o
pst
You also seem to be thinking in the wrong language… "`int future`" :)
deceze
Haha, true. Thanks guys.
infamouse
+3  A: 

Sure.

Get the current timestamp. Add 7 days worth of seconds.

Note: The timestamp "7 days ahead" (in terms of 7 * 86400 seconds) of the current timestamp may not represent the same day-of-week or the same hour in the day (yay daylight savings!) or even the same second (rare, yay leap-seconds!).

pst
+1  A: 

Just add seven days?

$future = time() + 60*60*24*7;
//      seconds  ---^  ^ ^  ^ 
//        minutes   ---^ ^  ^
//          hours     ---^  ^      
//            days       ---^

See time().... oh, the example given there does exactly what you want... I guess you have not read the manual before.

Felix Kling
+3  A: 
time() + (60 * 60 * 24 * 7);  // "good enough"
strtotime('+7 days');         // daylight savings save
deceze
A: 
$now = time() + (7 * 24 * 60 * 60);

Get the current unix timestamp using time() and then multiply 60 seconds, 60 minutes, 24 hours, and 7 days.

Justin Lucas
+1  A: 

The proper way of doing this on a recent version of PHP is using the DateTime object (in my opinion).

$date = new DateTime('now'); // can be anyting else too
$date->modify('+1 week');

// PHP 5.3
$future = $date->getTimeStamp(); 

// PHP 5.2
$future = $date->format('U');
Evert
I think that's a bit verbose as opposed to just doing `strtotime('+7 days');` as suggested by deceze and infamouse...
Cam