Skip to content
Advertisement

How to generate random date between two dates using php?

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 :

JavaScript

Advertisement

Answer

PHP has the rand() function:

JavaScript

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

JavaScript

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

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement