PDA

View Full Version : incrementing dates by month not days?


qaos
March 15th, 2007, 05:03 PM
How do you increment a date by months?

EG: Date.today + 5 months?

I would like to take a date (1/3/2007) and add (subtract) a number of months to it. I know I can add days (Date.today+5 => 5 days into the future of today's date). But How do you change 1/3/2007 + 5 months => 6/3/2007, or conversely 1/3/2007 - 5 months => 8/3/2006

Qaos.


I just found it.

Use '<<' or '>>'

sorry for the wasted space.

jolim
April 10th, 2007, 09:57 PM
Gotcha! For example:

@thisdate = Date.new

#reset to a month higher
@thisdate = @thisdate >> 1

Is there a shortcut for the operator? (like a += kind of thing?)

Thanks for the help