Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Date#>>

(::Integer month) -> ::Date
d >> n → new_date

Returns a new Date object representing the date n months later; n should be a numeric:

Example
(Date.new(2001, 2, 3) >> 1).to_s  # => "2001-03-03"
(Date.new(2001, 2, 3) >> -2).to_s # => "2000-12-03"

When the same day does not exist for the new month, the last day of that month is used instead:

Example
(Date.new(2001, 1, 31) >> 1).to_s  # => "2001-02-28"
(Date.new(2001, 1, 31) >> -4).to_s # => "2000-09-30"

This results in the following, possibly unexpected, behaviors:

Example
d0 = Date.new(2001, 1, 31)
d1 = d0 >> 1 # => #<Date: 2001-02-28>
d2 = d1 >> 1 # => #<Date: 2001-03-28>

d0 = Date.new(2001, 1, 31)
d1 = d0 >> 1  # => #<Date: 2001-02-28>
d2 = d1 >> -1 # => #<Date: 2001-01-28>
See also #=== #ajd #<=> #amjd also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0