2

I have a :dob (date of birth) attribute and if I if I call it in a view it appears in a YYYY-MM-DD format. Where can I set the default to a MM-DD-YYYY or some other variation? I would prefer to have it as "January 28th, 1990" and can do that in the view with dob.to_formatted_s(:long_ordinal) but would prefer to have a default to keep the code in my view a little nicer.

Alok Swain
  • 6,409
  • 5
  • 36
  • 57

2 Answers2

4
# config/initializers/date_formats.rb
Date::DATE_FORMATS[:default] = "%m/%d/%Y"
Alok Anand
  • 3,346
  • 1
  • 20
  • 17
1

You can change the format by overriding the default date format for ActiveSupport.

In config/environment.rb add this line

Date::DATE_FORMATS.merge!(:default => "%m/%d/%Y")
Alok Swain
  • 6,409
  • 5
  • 36
  • 57