How to add 10 days to current time in Rails

Yuval Karmi picture Yuval Karmi · Jan 11, 2011 · Viewed 118.1k times · Source

I tried doing something like

Time.now + 5.days

but that doesn't work, even though I vaguely remember seeing, and being very impressed, with being able to do something like 2.years etc.

How do I do that in Rails 3?

Answer

gunn picture gunn · Jan 11, 2011

Use

Time.now + 10.days

or even

10.days.from_now

Both definitely work. Are you sure you're in Rails and not just Ruby?

If you definitely are in Rails, where are you trying to run this from? Note that Active Support has to be loaded.