Skip to content
instance method

Date#-

(::Numeric & ::_ToR other) -> ::Date
(::Date other) -> ::Rational
d - other → date or rational

If the other is a date object, returns a Rational whose value is the difference between the two dates in days. If the other is a numeric value, returns a date object pointing other days before self. If the other is a fractional number, assumes its precision is at most nanosecond.

Example
Date.new(2001,2,3) - 1   #=> #<Date: 2001-02-02 ...>
DateTime.new(2001,2,3) - Rational(1,2)
                         #=> #<DateTime: 2001-02-02T12:00:00+00:00 ...>
Date.new(2001,2,3) - Date.new(2001)
                         #=> (33/1)
DateTime.new(2001,2,3) - DateTime.new(2001,2,2,12)
                         #=> (1/2)
See also #+ #<< .xmlschema #<=> also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0