Date formats in ActiveRecord / Rails 3
Posted
by cbmeeks
on Stack Overflow
See other posts from Stack Overflow
or by cbmeeks
Published on 2010-06-02T12:42:33Z
Indexed on
2010/06/03
9:24 UTC
Read the original article
Hit count: 377
In my model, I have a departure_date and a return_date.
I am using a text_field instead of the date_select so that I can use the JQuery datepicker.
My app is based in the US for now but I do hope to get international members.
So basically this is what is happening. The user (US) types in a date such as 04/01/2010 (April 1st).
Of course, MySQL stores it as a datetime such as 2010-04-01...
Anyway, when the user goes to edit the date later on, it shows "01/04/2010" because I am using a strftime("%m/%d/%Y) which doesn't make sense....so it thinks it is January 4th instead of the original April 1st.
It's like the only way to accurately store the data is for the user to type in: 2010-04-01
I hope all of this makes sense. What I am really after is a way for the user to type in (or use the datepicker) a date in their native format.
So someone in Europe could type in 01/04/2010 for April 1st but someone in the US would type in 04/01/2010.
Is there an easy, elegant solution to this?
Thanks for any suggestions.
© Stack Overflow or respective owner