Search code examples
phpdatetimestampunix-timestamp

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


Solution

  • 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);