From: Raimon Fs Date: 2007-12-07T22:57:49+09:00 Subject: Re: How do I add x months to a date Lloyd Linklater wrote: > Ben Edwards wrote: >> I have a date >> >> my_date = Date.new( 2007, 1, 1 ) >> >> I then have a variable holding an integer >> >> months_to_add = 4 >> >> How do i add 'months_to_add' to my_date'? >> >> I have spent ages googeling and looking in o'reilly ruby cookbook but no >> luck;( >> >> Any ideas? >> >> Ben > > I have not tried this but I know of something in rails that sounds > similar: > http://railshelp.com/ActiveSupport::CoreExtensions::Date::Calculations#months_ago I wasn't aware of this, thanks !!! I'm using Rails so I'll try to use it. I prefer to do in Ruby if it's possible ... > What if you could do something like this: > > my_date = Date.new( 2007, 1, 1 ) > months_to_add = 4 > my_date = my_date.months_ago(months_to_add * -1) > > Negative of months_ago could do it. > > Shot in the dark but GL! I'll try it ... thanks, rai -- Posted via http://www.ruby-forum.com/.