Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

random datetime ruby

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
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby hash.each 
Ruby :: ruby each do method 
Ruby :: rails check if a URL is valid 
Ruby :: ruby for loop 
Ruby :: ruby rails controller 
Ruby :: ruby rails where not in 
Ruby :: rails store array in database 
Ruby :: ruby activerecord find where less than 
Ruby :: dictionary ruby 
Ruby :: ruby while loop 
Ruby :: ruby conditionals 
Ruby :: generate dates using period rails 
Ruby :: how to run ruby classes 
Ruby :: rails automatically downcase on create 
Ruby :: object service 
Ruby :: ruby array with unique values 
Ruby :: crashed" method=GET path="/" rails 
Ruby :: important topic on ruby 
Ruby :: minimum of 3 elements 
Ruby :: how to access function defined in model rails 
Ruby :: diff between .. and ... in ruby 
Ruby :: rails db:drop not working 
Ruby :: Range extraction: convert a comma separated list of integers into range format 
Ruby :: ruby decode base64 
R :: add a vertical line in ggplot 
R :: dplyr colnames r 
R :: how to convert all columns of a dataframe into factors in r 
R :: list to dataframe in r 
R :: nls in r 
R :: ggplot2 graph in r 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =