Frank
Frank

Reputation: 1864

Generating random unix timestamp for tomorrow's date

I'm trying to generate a random unix timestamp for the following day in PHP. Could anyone point me into the right direction as to how this could be done?

Thanks! Frank

Upvotes: 0

Views: 702

Answers (2)

Alex Peng
Alex Peng

Reputation: 451

I think this could work:

$tomorrow_time = strtotime("tomorrow") + rand(0, 86400);

Basically, I get tomorrow midnight time and then add random second from 0 to 86400 (24 hours)

Upvotes: 0

bnlucas
bnlucas

Reputation: 1754

If you mean a random timestamp between 12:00am and 11:59pm you can do:

$tomorrow0000 = mktime(0, 0, 0, date('n'), date('d')+1, date('Y')); // midnight tomorrow
$tomorrow2359 = mktime(0, 0, 0, date('n'), date('d')+2, date('Y')) - 1; // midnight next day minus 1 second

$random = mt_rand($tomorrow0000, $tomorrow2359);

Upvotes: 3

Related Questions