ruby on rails - Iterate over records created_at dates and update with half of time from Time.now -
i want iterate on large collection of records in console, divide date half of time since time.now , save it. records created_at 2 months ago 1 month old, 1 day becomes 12 hours etc.
this doesn't work example:
log.all.each{|l| l.created_at = l.created_at - (time.now - l.created_at * 0.5); l.save}
try:
log.all.each{|l| l.created_at = time.at( l.created_at.to_f + (time.now.to_f - l.created_at.to_f)/2 ); l.save}
which should same as:
log.all.each{|l| l.created_at = time.at( (time.now.to_f + l.created_at.to_f)/2 ); l.save}
Comments
Post a Comment