From: Stefano Taschini Date: 2006-04-27T22:30:56+09:00 Subject: Re: Day number delta You might want to require mathn as well: require 'date' require 'mathn' Date.new(2006,4,28) - Date.new(2005,3,17) #=> 407 Ciao, Stefano On 27/04/06, Kirk Haines wrote: > On Thursday 27 April 2006 6:30 am, Lindsay Boyd wrote: > > How can I calculate the number of days between two Date objects?. This > > is easy enough with Time objects using the epoch seconds method tv_sec. > > Is there something similar for Dates? > > delta = a - b > > Just subtract one from the other. > > irb(main):001:0> require 'date' > => true > irb(main):002:0> a = Date.new(2006,4,28) > => # > irb(main):003:0> b = Date.new(2005,3,17) > => # > irb(main):004:0> c = a - b > => Rational(407, 1) > irb(main):005:0> c.to_i > => 407 > > > Kirk Haines > >