From: Ben Edwards Date: 2007-07-04T00:22:24+09:00 Subject: Re: How do I add x months to a date On 03/07/07, Glen Holcomb wrote: > And when I say string you could do better and use a hash or an array. > > On 7/3/07, Glen Holcomb wrote: > > > > You can't do it directly, date objects are immutable. > > > > You could always get the date value from the object and then parse it, add > > the number of months you want and then create a new date object. That > > seems > > like a bit of a waste though. I would keep the date value in a string and > > manipulate it there, if and when I needed an actual date object with that > > value I would create a date object and give that out. This all seems like a lot of messing around for what should be a standard operation. This type of thing must exist in one of the standard libraries. Ben > > On 7/3/07, 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 > > > -- > > > Ben Edwards - Bristol, UK > > > If you have a problem emailing me use > > > http://www.gurtlush.org.uk/profiles.php?uid=4 > > > (email address this email is sent from may be defunct) > > > > > > > > > > > > -- > > "Hey brother christian with your high and mighty errand, Your actions > > speak > > so loud, I can't hear a word you're saying." > > > > -Greg Graffin (Bad Religion) > > > > > > -- > "Hey brother christian with your high and mighty errand, Your actions speak > so loud, I can't hear a word you're saying." > > -Greg Graffin (Bad Religion) > -- Ben Edwards - Bristol, UK If you have a problem emailing me use http://www.gurtlush.org.uk/profiles.php?uid=4 (email address this email is sent from may be defunct)