Reputation: 2363
I'm trying to find a way to figure out "3 years from now on x date" where x date is not today.
def xmas
self.new_xmas = @given_date + 3.years
end
I'm stuck on how to make sure it's December 25th 3 years from @given_date
Upvotes: 1
Views: 686
Reputation: 34318
You can simply do this:
require 'date'
given_date = Date.today # you can change it to any date
puts "given_date: #{given_date}"
current_year = given_date.year # grab the current year from the given_date
third_xmas_from_given_date = Date.new(current_year + 3, 12, 25) # add 3 years to the current_year (change it according to your need)
puts "third_xmas_from_given_date: #{third_xmas_from_given_date}"
# => given_date: 2015-11-09
# => third_xmas_from_given_date: 2018-12-25
Upvotes: 1