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);
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);
The best way :
By using carbon and php rand between two dates
OR
PHP has the rand() function:
It also has mt_rand(), which is generally purported to have better randomness in the results:
To turn a timestamp into a string, you can use date(), ie:
If given dates are in date time format then use this easiest way of doing this is to convert both numbers to timestamps, then set these as the minimum and maximum bounds on a random number generator.
A quick PHP example would be:
This function makes use of strtotime() as suggested by zombat to convert a datetime description into a Unix timestamp, and date() to make a valid date out of the random timestamp which has been generated.
An other solution where we can use date_format :
Source : https://gist.github.com/samcrosoft/6550473
You could use for example :
Full random date and time