Skip to content

Instantly share code, notes, and snippets.

@Linell
Last active August 29, 2015 14:11
Show Gist options
  • Save Linell/cad1bd242ea8f49312ab to your computer and use it in GitHub Desktop.
Save Linell/cad1bd242ea8f49312ab to your computer and use it in GitHub Desktop.
Generates a random date between two given dates.
def random_date
date1 = DateTime.new(2014,8,1)
date2 = DateTime.now()
Time.at( (date2.to_f - date1.to_f)*rand + date1.to_f).to_date
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment