Ruby Date Subtraction (e.g. 90 days Ago)
require 'date'now = Date.todayninety_days_ago = (now - 90)
Running this thru the IRB console I get:
>>require 'date'now = Date.todayninety_days_ago = (now - 90)require 'date'=> falsenow = Date.today=> #<Date: 2011-03-02 (4911245/2,0,2299161)>ninety_days_ago = (now - 90)=> #<Date: 2010-12-02 (4911065/2,0,2299161)>
If you need the time you could just say now = DateTime.now
If you're using Rails or don't mind including ActiveSupport, you can use the Numeric#days DSL like this:
ruby-1.9.2-p136 :002 > Date.today => Wed, 02 Mar 2011 ruby-1.9.2-p136 :003 > Date.today - 90.days => Thu, 02 Dec 2010
Since you are working with dates instead of times, you should also either start with Date instances, or convert your DateTime intances with #to_date. When adding/subtracting numbers from date instances, the numbers are implicitly days.
ruby-1.9.2-p136 :016 > DateTime.now.to_date => #<Date: 2011-03-02 (4911245/2,0,2299161)> ruby-1.9.2-p136 :017 > DateTime.now.to_date - 90 => #<Date: 2010-12-02 (4911065/2,0,2299161)>