Reputation: 135
What I would like to do is to go from "2013", "December", "20" and to create 2013-12-20.
Does someone have an idea ? Thanks !
Upvotes: 0
Views: 73
Reputation: 16506
This is an extension to @Marc-Alexandre Bérubé 's answer to get your desired format:
"20 december 2013".to_date.strftime("%Y-%m-%d")
# => "2013-12-20"
Upvotes: 1
Reputation: 61
You can do this:
Date.new(2013, 12, 20)
You can read more about Date here
Upvotes: 1
Reputation: 733
For your required format you can use this bit for formatting:
strftime("The date is %y-%m-%d")
This can be called on any time object.
Upvotes: 1
Reputation: 2171
Rails provide nice converters in part of it's framework
2.1.2 :001 > "20 december 2013".to_date
=> Fri, 20 Dec 2013
Upvotes: 2