简体   繁体   中英

Rails 3, MySQL Production only allows dates in mm/dd/yyyy or yyyy-mm-dd format need to input in dd/mm/yyyy

I have been working on a Rails 3 app and on my development environment everything has worked fine. The dev environment is Ubuntu 10.10 Desktop running mysql, Time location is Europe - London.

I can enter dates in UK dd/mm/yyyy format and these save to the database without any difficulty. I understand that MySQL stores the dates in yyyy-mm-dd format.

In production however I can only enter dates in mm/dd/yyyy or yyyy-mm-dd format. This is an internal application and my users would like to obviously enter dates in our native format.

The server is Ubuntu 10.10 server running mysql. Time location is Europe London.

I can easily sort the displaying of the date by using .strftime("%d/%m/%Y")

I found somewhere somebody suggested adding Date::DATE_FORMATS[:default] = "%d/%m/%Y" to the environments.rb file this hasn't worked.

And then somewhere else suggested adding Date.strptime(params[:work_order][:recieved_date], "%d/%m/%Y"))

This has actually stopped my development working (I added this to my create action in the controller)

run this on your production mysql server

SELECT @@lc_time_names;

You might want it to be "en_GB" unsure about what standard there is in the UK, you can probably set it in the mysql configuration files, maybe my.cnf.

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_lc_time_names

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM