Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Date.parse

Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) → date

Parses the given representation of date and time, and creates a date object.

This method **does not** function as a validator. If the input string does not match valid formats strictly, you may get a cryptic result. Should consider to use Date.strptime instead of this method as possible.

If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.

Example
Date.parse('2001-02-03')          #=> #<Date: 2001-02-03 ...>
Date.parse('20010203')            #=> #<Date: 2001-02-03 ...>
Date.parse('3rd Feb 2001')        #=> #<Date: 2001-02-03 ...>

Raise an ArgumentError when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.

See also ._parse ._rfc2822 .ordinal .rfc2822 also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1