Random Datetime Ruby

[Solved] Random Datetime Ruby | Ruby - Code Explorer | yomemimo.com
Question : random datetime ruby

Answered by : tense-turtle-bspt2d8k5igu

def time_rand from = 0.0, to = Time.now Time.at(from + rand * (to.to_f - from.to_f))
end
> time_rand => 1977-11-02 04:42:02 0100
> time_rand Time.local(2010, 1, 1) => 2010-07-17 00:22:42 0200
> time_rand Time.local(2010, 1, 1), Time.local(2010, 7, 1) => 2010-06-28 06:44:27 0200

Source : https://duckduckgo.com/?q=faker+random+datetime+ruby+&atb=v306-6&ia=web | Last Update : Tue, 11 Jan 22

Answers related to random datetime ruby

Code Explorer Popular Question For Ruby