Topic: substracting days from Date

I would like to go back 14 days (or months, or years) from today's date. How would I do that?

I tried

Date.today.day - 10

. This returns the days minus 10 days, but does not return the whole date. So for example, if today's date is 2006-11-10 and I want to go back 14 days, I want the date to be returned as 2006-10-27. Format doesn't matter. I am just using 'YYYY-MM-DD'.

Thanks for the help!

Last edited by Jammer1982 (2006-11-10 11:46:46)

Re: substracting days from Date

Try

Date.today - 10

Re: substracting days from Date

Ok...I tried that initially and I was getting an error. But now I realize why I was getting that error. I was getting my offset from a params field, which resulted essentially in trying to substract a string from Date.today.

Date.today - offset

Instead, I tried:
Date.today - offset.to_i

which is working perfectly.

Thank you!