Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Formatting text in date_field

date_field

  • Please log in to reply
2 replies to this topic

#1 jockeberg

jockeberg

    Passenger

  • Members
  • 1 posts

Posted 05 January 2014 - 12:44 AM

I have a date_field that's added to the view like this:

<%= f.date_field :date, required: true %>

It works nicely but the format of the text in the field is mm/dd/yyyy. I would like it to be yyyy-mm-dd. I've tried the suggestions here: http://stackoverflow...-to-be-ddmmyyyy but adding this:

# config/environments/development.rb (yes I'm trying it in develop).

my_date_formats = { :default => '%Y-%m-%d' } 
Date::DATE_FORMATS.merge!(my_date_formats)

# Or this that I found in another suggestion.

Date::DATE_FORMATS[:default]="%Y-%m-%d"

Or this:

# config/locales/en.yml

en:
  date:
    formats:
      default: "%Y-%m-%d"

All still result in the field showing the date as mm/dd/yyyy. Any other suggestions on how to accomplish this?



#2 RoyTheB0y

RoyTheB0y

    Signalman

  • Members
  • 10 posts

Posted 09 January 2014 - 09:43 PM

have you looked at datepicker, i think Ryan talks about changing the date formats in his railscast 

 

http://railscasts.co...s/213-calendars



#3 himanshu339

himanshu339

    Passenger

  • Members
  • 9 posts

Posted 17 March 2014 - 08:33 AM

why dont you try using "12/12/2014".split('/').join('-').

 

This will convert date format.

 

Hope this helps!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users