Skip to content

Instantly share code, notes, and snippets.

View richkettle's full-sized avatar

Richard Kettle richkettle

  • BookingBug
  • London
View GitHub Profile
@richkettle
richkettle / random_date.rb
Last active November 11, 2020 11:52
Random date in sql.
from = (Time.now - 1.year).to_i
to = Time.now.to_i
sql = "update table_name set created_at = FROM_UNIXTIME(RAND() * (#{to} - #{from}) + #{from});"
records_array = ActiveRecord::Base.connection.execute(sql)