From: Raimon Fs Date: 2007-12-07T19:53:56+09:00 Subject: Re: How do I add x months to a date Daniel Lucraft wrote: > Ben Edwards wrote: >> On 03/07/07, Glen Holcomb wrote: >>> > 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 > > Actually, you are totally right. The '>>' operator does what is > required: > > irb> my_date = Date.new( 2007, 1, 1 ) > => # > > irb> my_date.to_s > => "2007-01-01" > irb> (my_date >> 4).to_s > => "2007-05-01" > > best, > Dan I couldn't find any info about this operator >> with dates. So, for example, if I have 2007-01-01 and I want to know the last day of adding three months (2007-03-31) I would do: d = Date.new(2007,1,1) ((d >> 3)-1).to_s it works, but we can relay on this operations ? regards, rai -- Posted via http://www.ruby-forum.com/.