Skip to content

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

class method

Date.ordinal

(?::Integer year, ?::Integer yday, ?::Integer start) -> ::Date
Date.ordinal(year = -4712, yday = 1, start = Date::ITALY) → date

Returns a new Date object formed fom the arguments.

With no arguments, returns the date for January 1, -4712:

Example
Date.ordinal.to_s # => "-4712-01-01"

With argument year, returns the date for January 1 of that year:

Example
Date.ordinal(2001).to_s  # => "2001-01-01"
Date.ordinal(-2001).to_s # => "-2001-01-01"

With positive argument yday == n, returns the date for the nth day of the given year:

Example
Date.ordinal(2001, 14).to_s # => "2001-01-14"

With negative argument yday, counts backward from the end of the year:

Example
Date.ordinal(2001, -14).to_s # => "2001-12-18"

Raises an exception if yday is zero or out of range.

See argument start.

Related: Date.jd, Date.new.

See also .new ._parse .leap? .parse also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0