tags:

views:

102

answers:

2

How do I create a Ruby date object from this string "DD-MM-YYYY"?

+4  A: 

You can use Time#parse.

Time.parse("20-08-2010")
# => Fri Aug 20 00:00:00 +0200 2010

However, because Ruby could parse the date as "MM-DD-YYYY", the best way is to go with DateTime#strptime where you can specify the input format.

Simone Carletti
+4  A: 
Date.parse('31-12-2010')

Alternatively Date#strptime(str, format).

deceze