Hermine D. Hermine D. - 1 year ago 64
Ruby Question

How to generate a random date and time between two dates?

Don't overlook the 'date AND TIME' part though.

Answer Source
Time.at((date2.to_f - date1.to_f)*rand + date1.to_f)

You'll get a time object that is between two given datetimes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download