Method: String#to_date

Defined in:
activesupport/lib/active_support/core_ext/string/conversions.rb

#to_dateObject

Converts a string to a Date value.

"1-1-2012".to_date   # => Sun, 01 Jan 2012
"01/01/2012".to_date # => Sun, 01 Jan 2012
"2012-12-13".to_date # => Thu, 13 Dec 2012
"12/13/2012".to_date # => ArgumentError: invalid date


47
48
49
# File 'activesupport/lib/active_support/core_ext/string/conversions.rb', line 47

def to_date
  ::Date.parse(self, false) unless blank?
end