Update only year in timestamps [SOLVED]

Viewed 41

I have a timestamp column start_date in one model that I want to use to update the start_date column of another model but updates the will be only on year part for some records based on certain logic. My code is something similar to this:

Model1.each do |record|
  model_2_instance = find_model2_record(record) # based on some logic
  diff = model_2_instance.start_date.year - record.start_date.year
  new_start_date = record.start_date - diff  # this won't work. I want a solution for this calculation.

  model_2_instance.update(start_date: new_start_date )
end

I want a solution for the new_start_date calculation in the above loop. Thanks for the help in advance.

0 Answers
Related