From: Lloyd Linklater Date: 2007-12-07T21:34:05+09:00 Subject: Re: How do I add x months to a date 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 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! -- Posted via http://www.ruby-forum.com/.