method

to_date

Importance_2
v2.2.1 - Show latest stable - 2 notes - Class: ActiveSupport::CoreExtensions::String::Conversions
to_date() public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Show source
Register or log in to add new notes.
July 13, 2008
5 thanks

Convert strings to Dates

Uses the undocumented Date._parse method. Some usage examples:

'06/15/2008'.to_date         # => Sun, 15 Jun 2008
'20080615'.to_date           # => Sun, 15 Jun 2008
'2008-06-15'.to_date         # => Sun, 15 Jun 2008
'Sun, 15 Jun 2008'.to_date   # => Sun, 15 Jun 2008
July 25, 2008
2 thanks

If you need something more

Use the brilliant chronic gem: http://chronic.rubyforge.org/

require 'chronic'
Time.now # => Fri Jul 25 00:00:25 0200 2008
Chronic.parse 'tomorrow 8 in the evening'  # => Sat Jul 26 20:00:00 0200 2008
Chronic.parse 'next Monday noon'           # => Mon Jul 28 12:00:00 0200 2008
Chronic.parse 'first Wednesday of Aug'     # => Wed Aug 06 12:00:00 0200 2008
Chronic.parse 'first Wednesday of Aug 7pm' # => Wed Aug 06 19:00:00 0200 2008