Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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 !
Rails provide nice converters in part of it's framework
2.1.2 :001 > "20 december 2013".to_date => Fri, 20 Dec 2013
Add a comment
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.
You can do this:
Date.new(2013, 12, 20)
You can read more about Date here
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"
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.