How to generate random date between two dates using php?

前端 未结 13 1908
甜味超标
甜味超标 2020-11-27 15:55

I am coding an application where i need to assign random date between two fixed timestamps

how i can achieve this using php i\'ve searched first but only found the a

13条回答
  •  孤城傲影
    2020-11-27 16:24

    PHP has the rand() function:

    $int= rand(1262055681,1262055681);
    

    It also has mt_rand(), which is generally purported to have better randomness in the results:

    $int= mt_rand(1262055681,1262055681);
    

    To turn a timestamp into a string, you can use date(), ie:

    $string = date("Y-m-d H:i:s",$int);
    

提交回复
热议问题