Minus one DateTime from another : Date Calculation « Date « Ruby






Minus one DateTime from another


require 'date'
day_one = DateTime.new(1999, 12, 31)
day_two = DateTime.new(2000, 1, 1)
day_two - day_one                           # => Rational(1, 1)
day_one - day_two                           # => Rational(-1, 1)

 








Related examples in the same category

1.Subtract 61 days from a date:
2.Add and subtract six months using the >> and << methods.
3.Doing Date Arithmetic
4.Doing DateTime Arithmetic
5.Move DateTime
6.leap year day
7.Counting the Days Since an Arbitrary Date
8.advent calendar
9.Minus DateTime by day
10.Remaining days