From: Rick DeNatale Date: 2007-12-08T01:45:00+09:00 Subject: Re: How do I add x months to a date On 12/7/07, Raimon Fs wrote: > 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 ? It's standard Ruby shadowfax:~/ssanta rick$ qri "Date#<<" ---------------------------------------------------------------- Date#<< <<(n) ------------------------------------------------------------------------ Return a new Date object that is n months earlier than the current one. If the day-of-the-month of the current Date is greater than the last day of the target month, the day-of-the-month of the returned Date will be the last day of the target month. shadowfax:~/ssanta rick$ qri "Date#>>" ---------------------------------------------------------------- Date#>> >>(n) ------------------------------------------------------------------------ Return a new Date object that is n months later than the current one. If the day-of-the-month of the current Date is greater than the last day of the target month, the day-of-the-month of the returned Date will be the last day of the target month. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/