0

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 !

4 Answers 4

2

Rails provide nice converters in part of it's framework

2.1.2 :001 > "20 december 2013".to_date
 => Fri, 20 Dec 2013
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

You can do this:

Date.new(2013, 12, 20)

You can read more about Date here

Comments

1

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"

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.