How to generate random date between two dates using php?

M.E picture M.E · Dec 29, 2009 · Viewed 76.9k times · Source

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 answer for Java not php

for example :

$string = randomdate(1262055681,1262055681);

Answer

zombat picture zombat · Dec 29, 2009

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