1

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

Would be awesome!

3

6 Answers 6

11

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'))
1
  • 3
    You also seem to be thinking in the wrong language… "int future" :)
    – deceze
    Jul 21, 2010 at 23:12
6

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!).

4
time() + (60 * 60 * 24 * 7);  // "good enough"
strtotime('+7 days');         // daylight savings save
2

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.

1

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');
1
  • I think that's a bit verbose as opposed to just doing strtotime('+7 days'); as suggested by deceze and infamouse...
    – Cam
    Jul 21, 2010 at 23:21
0
$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.

1
  • 1
    You shouldn't call the variable $now as this is misleading since it is not actually the time now, it's the time 1 week from now.
    – B3none
    May 24, 2018 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.