# Changing default date format in Rails

**URL:** <https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779>\
**Category:** Rails\
**Created:** [March 14, 2006, 5:02am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779 "2006-03-14T05:02:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 14, 2006, 5:02am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/1 "2006-03-14T05:02:10Z")

</div>

I’ve spent all day digging through the rails api and postgres-pr on  
this, I think it’s time to ask the list.

Postgres stores a Date in YYYY-MM-DD format. My users want the dates  
in MM/DD/YYYY format.

Sure, I could explicitly convert it on the app level every place where  
a date is displayed, but that seemed like a DRY violation.

I thought I’d be clever and simply redefine Date.to\_s with

class Date  
def to\_s  
strftime(’%m/%d/%Y’)  
end  
end

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 14, 2006, 5:11am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/2 "2006-03-14T05:11:22Z")

</div>

On Mon, 2006-03-13 at 20:01 -0800, Dav Y. wrote:

> class Date  
> def to\_s  
> strftime(’%m/%d/%Y’)  
> end  
> end

* * *

I don’t know the answer but I appreciate the question…that one is on  
my todo list so when you do get a resolve on it, please post back to the  
list.

Craig

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 14, 2006, 9:18am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/3 "2006-03-14T09:18:49Z")

</div>

Dav Y. wrote:

> I’ve spent all day digging through the rails api and postgres-pr on  
> this, I think it’s time to ask the list.
> 
> Postgres stores a Date in YYYY-MM-DD format. My users want the dates  
> in MM/DD/YYYY format.
> 
> Sure, I could explicitly convert it on the app level every place where  
> a date is displayed, but that seemed like a DRY violation.

There’s already a nice way to do this. ActiveSupport enhances Date#to\_s  
to take a format parameter. Fire up script/console and look at the value  
of this hash:  
ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS

If you add an entry for :default, that will be used for all to\_s  
conversions where you don’t specify a format. And you can use  
some\_date.to\_s(:db) to output in the format for your database. If you  
want to change or add formats, put something like this in your  
environment.rb after the end of the Initializer block:

ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS.merge!(  
:default =\> ‘%m/%d/%Y’,  
:date\_time12 =\> “%m/%d/%Y %I:%M%p”,  
:date\_time24 =\> “%m/%d/%Y %H:%M”,  
)

–josh  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 14, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/4 "2006-03-14T17:25:31Z")

</div>

Josh S. wrote:

> Dav Y. wrote:
> 
> > I’ve spent all day digging through the rails api and postgres-pr on  
> > this, I think it’s time to ask the list.
> > 
> > Postgres stores a Date in YYYY-MM-DD format. My users want the dates  
> > in MM/DD/YYYY format.
> > 
> > Sure, I could explicitly convert it on the app level every place where  
> > a date is displayed, but that seemed like a DRY violation.
> 
> There’s already a nice way to do this. ActiveSupport enhances Date#to\_s  
> to take a format parameter. Fire up script/console and look at the value  
> of this hash:  
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS
> 
> If you add an entry for :default, that will be used for all to\_s  
> conversions where you don’t specify a format. And you can use  
> some\_date.to\_s(:db) to output in the format for your database. If you  
> want to change or add formats, put something like this in your  
> environment.rb after the end of the Initializer block:
> 
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS.merge!(  
> :default =\> ‘%m/%d/%Y’,  
> :date\_time12 =\> “%m/%d/%Y %I:%M%p”,  
> :date\_time24 =\> “%m/%d/%Y %H:%M”,  
> )

Oops, two small corrections. (No more late night postings!) For a Date,  
you want to use this hash:  
ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS

> And you can use some\_date.to\_s(:db) to output in the format for your database.

By the above I meant that Rails uses the :db formatter when converting a  
date to a string to use in a database query. So if you need to you can  
change the :db format and the way dates are formatted for the database  
will change automatically.

–josh  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [July 31, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/5 "2006-07-31T18:26:37Z")

</div>

Dan,

Just to solve this particular problem with date formats with  
in\_place\_editor\_field, I just augmented my model. Originally, I had a  
date of birth field called dob. I did this in the model:

def dob\_formatted  
dob.strftime ‘%m/%d/%Y’  
end’

def dob\_formatted=(value)  
self.dob = Time.parse(value)  
end

Then in the view:

\<%= in\_place\_editor\_field :client, ‘dob\_formatted’ %\>

HTH,  
Ed

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 14, 2006, 8:48pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/6 "2006-03-14T20:48:07Z")

</div>

Argh, Gmail ate over half of my original post so I didn’t actually  
explain myself.

Josh, thanks for the tip on the CoreExtension stuff. Unfortunately it  
doesn’t really help.

The problem is that both the DATE\_FORMATS thing, and my Date.to\_s  
overwrite, don’t extend deep enough into the rails system. It works  
great once you have a model object and are just calling the attribute  
reader methods on it, but when you use the ActionView helpers like  
text\_field or in\_place\_editor the customized default does come into  
play. By digging into the rails code, I found that this is because  
these tag helpers end up calling object.attribute\_before\_type\_cast  
which simply returns the raw string from the sql results. Let me  
illustrate:

script/console  
Loading development environment.

> > ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS  
> > =\> {:short=\>“%e %b”, :long=\>“%B %e, %Y”}

> > Date.today.to\_s  
> > =\> “2006-03-14”

> > ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS[:default]=‘%m/%d/%Y’  
> > =\> “%m/%d/%Y”

> > Date.today.to\_s  
> > =\> “03/14/2006”

(w00t)

> > r = Rebate.find 30  
> > =\> #\<Rebate:0x2276778 @attributes={“reminder\_list”=\>“0”,  
> > “status”=\>“2”, “prorated”=\>“0”, “updated\_at”=\>nil,  
> > “service\_period”=\>“14”, “employee\_id”=\>“1”, “id”=\>“30”,  
> > “customer\_id”=\>“30”, “reminder\_cancel\_date”=\>nil, “amount”=\>“300.00”,  
> > “credit\_on”=\>“2005-12-17”, “service\_fee”=\>“75.00”,  
> > “created\_at”=\>“2005-12-17 14:35:19”}\>

> > r.credit\_on.to\_s  
> > =\> “12/17/2005”

(w00t!)

> > av = ActionView::Base.new  
> > =\> #\<ActionView::Base:0x25779b8 @assigns\_added=nil, @controller=nil,  
> > @base\_path=nil, @assigns={}, @logger=nil\>

> > av.instance\_variable\_set(“@rebate”,r)  
> > =\> #\<Rebate:0x2276778 @attributes={“reminder\_list”=\>“0”,  
> > “status”=\>“2”, “prorated”=\>“0”, “updated\_at”=\>nil,  
> > “service\_period”=\>“14”, “employee\_id”=\>“1”, “id”=\>“30”,  
> > “customer\_id”=\>“30”, “reminder\_cancel\_date”=\>nil, “amount”=\>“300.00”,  
> > “credit\_on”=\>“2005-12-17”, “service\_fee”=\>“75.00”,  
> > “created\_at”=\>“2005-12-17 14:35:19”}\>

> > av.text\_field :rebate, ‘credit\_on’  
> > =\> “\<input id="rebate\_credit\_on" name="rebate[credit\_on]"  
> > size="30" type="text" value="2005-12-17" /\>”

(!w00t)

I don’t want to use a solution that requires me to give up on some of  
the nicer parts of RoR. So this is where I became stuck. I took some  
time to dig around in the ConnectionAdapter stuff, but I don’t see an  
easy way to do what I want through that level either, although to be  
honest I found some of the Postgres specific stuff confusing.

On 3/14/06, Josh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > And you can use some\_date.to\_s(:db) to output in the format for your database.  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Dav Y.  
[http://AkuAku.org/](http://AkuAku.org/)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 28, 2006, 9:40am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/7 "2006-08-28T09:40:49Z")

</div>

Kevin O. wrote:

> On Monday, July 31, 2006, at 11:25 AM, Ed Howland wrote:
> 
> > def dob\_formatted=(value)  
> > On 3/14/06, Dav Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > text\_field or in\_place\_editor the customized default does come into
> > > 
> > > > > Date.today.to\_s
> > > 
> > > “customer\_id”=\>“30”, “reminder\_cancel\_date”=\>nil, “amount”=\>“300.00”,  
> > > the nicer parts of RoR. So this is where I became stuck. I took some
> > > 
> > > > > > this, I think it’s time to ask the list.  
> > > > > > to take a format parameter. Fire up script/console and look at
> > > > 
> > > > ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS  
> > > > –josh
> > 
> > –  
> > Ed Howland  
> > [http://greenprogrammer.blogspot.com](http://greenprogrammer.blogspot.com)
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> Be careful changing the default format. I had an issue lately where  
> doing this completely hosed MySQL. Bottom line is that ActiveRecord was  
> trying to insert dates into the database in the new default format,  
> instead of the way MySQL was expecting to get it. It resulted in empty  
> dates, but no real error.
> 
> Twas quite a pain to track down.
> 
> \_Kevin  
> [www.sciwerks.com](http://www.sciwerks.com)

Did you ever figure out how to fix this? I have the same problem,  
changing the default date format effects the way it is passed to mysql.  
I would think that the rails team could fix this somehow no?

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 1, 2006, 1:50am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/8 "2006-08-01T01:50:16Z")

</div>

On Monday, July 31, 2006, at 11:25 AM, Ed Howland wrote:

> def dob\_formatted=(value)  
> On 3/14/06, Dav Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > text\_field or in\_place\_editor the customized default does come into
> > 
> > > > Date.today.to\_s
> > 
> > “customer\_id”=\>“30”, “reminder\_cancel\_date”=\>nil, “amount”=\>“300.00”,  
> > the nicer parts of RoR. So this is where I became stuck. I took some
> > 
> > > > > this, I think it’s time to ask the list.  
> > > > > to take a format parameter. Fire up script/console and look at
> > > 
> > > ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS  
> > > –josh
> 
> –  
> Ed Howland  
> [http://greenprogrammer.blogspot.com](http://greenprogrammer.blogspot.com)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Be careful changing the default format. I had an issue lately where  
doing this completely hosed MySQL. Bottom line is that ActiveRecord was  
trying to insert dates into the database in the new default format,  
instead of the way MySQL was expecting to get it. It resulted in empty  
dates, but no real error.

Twas quite a pain to track down.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [September 2, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/9 "2006-09-02T21:02:51Z")

</div>

I hope this is relevant, I’m just starting out on Ruby, and with Rails,  
and I ran into trouble with MySQL dates. Here’s how I got what I wanted:

# This method takes in a MySQL formatted date (YYYY-MM-DD)

# and returns a date formatted as (M/DD)

def format\_date(date)  
year, month, day = date.split(/-/) # splits date into 3  
variables  
month = month.sub(/^0/,’’) # Strips leading '0’s from the month  
month + “/” + day # concatenates and returns date  
end

I wasn’t sure how to get/use Date objects so I restricted myself to the  
String class.

I put this method in my helper file.

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [September 4, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/10 "2006-09-04T14:43:37Z")

</div>

Kris wrote:

> > > > > > > this, I think it’s time to ask the list.  
> > > > > > > removed\_email\_address@domain.invalid
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).  
> Not yet. That’s on the back burner for the moment. I’ve just been  
> using the default output for now and specifically changing it when  
> necessary.

I think the fix for this is to define a default :db date format and  
modify the appropriate AR code to use that format when writing to the  
DB. That way you could change the default print format without  
affecting the DB writes. I think I first encountered this while the  
Trac was down, so I’ll go submit a ticket on this (if there isn’t one  
already).

\_Kevin

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [June 25, 2007, 12:43pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/11 "2007-06-25T12:43:35Z")

</div>

Stuart R. wrote:

> > Did you ever figure out how to fix this? I have the same problem,  
> > changing the default date format effects the way it is passed to mysql.  
> > I would think that the rails team could fix this somehow no?
> 
> The problem seems to be solved in the post 1.2.1 Edge Rails revison  
> 6270, March 2007. See TRAC ticket [http://dev.rubyonrails.org/ticket/7411](http://dev.rubyonrails.org/ticket/7411)  
> (alternatively 1.2.1 users could patch the quote method in  
> lib/active\_record/connection\_adapters/abstract/quoting.rb).
> 
> I’ve written a howto along with a date validator, date\_field helper and  
> calendar control to address the whole date display/input/validation  
> question at [methods.co.nz](http://www.methods.co.nz/rails_date_kit/rails_date_kit.html)
> 
> Cheers, Staurt

Following this issue and guided by the Stuart’s howto I have written a  
post solving this issue in a different way. Besides, time formatting is  
also covered.

The post can be found here:

> **[Home](https://www.nominet.uk)**
>
> Welcome to Nominet - Official registry for .UK domain names. Discover our domain name registration services, Cyber solutions and WHOIS lookup tool

Cheers  
Miquel

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 1, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/12 "2007-08-01T21:13:16Z")

</div>

Hi Staurt,

I like your calendar but got into a weird problem where the calendar  
overlaps with a drop down select underneath it. I tried to fix it using  
the z-index in the css but not lock. It only overlaps with the drop down  
control and not with others like text box, text area, buttons, labels  
etc.

Any thoughts?

i\_programmer

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 1, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/13 "2007-08-01T21:19:16Z")

</div>

On 8/1/07, Dave M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Staurt,
> 
> I like your calendar but got into a weird problem where the calendar  
> overlaps with a drop down select underneath it. I tried to fix it using  
> the z-index in the css but not lock. It only overlaps with the drop down  
> control and not with others like text box, text area, buttons, labels  
> etc.
> 
> Any thoughts?

Windows?  
[http://www.devguru.com/features/tutorials/ComboControl/combocontrol.html](http://www.devguru.com/features/tutorials/ComboControl/combocontrol.html)

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 3, 2007, 6:40am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/14 "2007-03-03T06:40:43Z")

</div>

Kris wrote:

> > > Rails mailing list  
> > > removed\_email\_address@domain.invalid  
> > > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> > 
> > Be careful changing the default format. I had an issue lately where  
> > doing this completely hosed MySQL. Bottom line is that ActiveRecord was  
> > trying to insert dates into the database in the new default format,  
> > instead of the way MySQL was expecting to get it. It resulted in empty  
> > dates, but no real error.
> > 
> > Twas quite a pain to track down.
> > 
> > \_Kevin  
> > [www.sciwerks.com](http://www.sciwerks.com)
> 
> Did you ever figure out how to fix this? I have the same problem,  
> changing the default date format effects the way it is passed to mysql.  
> I would think that the rails team could fix this somehow no?

The problem seems to be solved in the post 1.2.1 Edge Rails revison  
6270, March 2007. See TRAC ticket [http://dev.rubyonrails.org/ticket/7411](http://dev.rubyonrails.org/ticket/7411)  
(alternatively 1.2.1 users could patch the quote method in  
lib/active\_record/connection\_adapters/abstract/quoting.rb).

I’ve written a howto along with a date validator, date\_field helper and  
calendar control to address the whole date display/input/validation  
question at [methods.co.nz](http://www.methods.co.nz/rails_date_kit/rails_date_kit.html)

Cheers, Staurt

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 30, 2007, 10:38am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/15 "2007-08-30T10:38:38Z")

</div>

Josh S. wrote:

> There’s already a nice way to do this. ActiveSupport enhances Date#to\_s  
> to take a format parameter. Fire up script/console and look at the value  
> of this hash:  
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS
> 
> If you add an entry for :default, that will be used for all to\_s  
> conversions where you don’t specify a format. And you can use  
> some\_date.to\_s(:db) to output in the format for your database. If you  
> want to change or add formats, put something like this in your  
> environment.rb after the end of the Initializer block:
> 
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS.merge!(  
> :default =\> ‘%m/%d/%Y’,  
> :date\_time12 =\> “%m/%d/%Y %I:%M%p”,  
> :date\_time24 =\> “%m/%d/%Y %H:%M”,  
> )
> 
> –josh  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

How can I tell to\_xml to format a date according to one of these  
predefined formats? Thanks,

Chris.

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 4, 2008, 6:19am UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/16 "2008-03-04T06:19:45Z")

</div>

Dave M. wrote:

> Hi Staurt,
> 
> I like your calendar but got into a weird problem where the calendar  
> overlaps with a drop down select underneath it. I tried to fix it using  
> the z-index in the css but not lock. It only overlaps with the drop down  
> control and not with others like text box, text area, buttons, labels  
> etc.
> 
> Any thoughts?
> 
> i\_programmer

This is an issue with Internet Explorer. The easiest way to fix this  
problem is by wrapping the div you want to be above the select box in an  
iframe. Here is a simple jquery plugin that demonstrates the technique.  
You should be able to easily port this to other JavaScript libraries to  
solve the issue.

[http://brandonaaron.net/jquery/plugins/bgiframe/jquery.bgiframe.js](http://brandonaaron.net/jquery/plugins/bgiframe/jquery.bgiframe.js)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [August 30, 2007, 2:36pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/17 "2007-08-30T14:36:50Z")

</div>

Chris Gers32 wrote:

> How can I tell to\_xml to format a date according to one of these  
> predefined formats? Thanks,
> 
> Chris.

I got a reply from Railsfrance; I just redefine XML\_FORMATTING locally,  
like this:

```
old_proc = Hash::XML_FORMATTING['datetime']
Hash::XML_FORMATTING['datetime'] = Proc.new { |datetime| 

```

datetime.to\_s(:rfc822) }

```
MY CODE THAT CALLS to_xml GOES HERE

Hash::XML_FORMATTING['datetime'] = old_proc

```

Chris.

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [December 15, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/18 "2009-12-15T17:07:45Z")

</div>

Hello,  
I found that the easiest way for me is using the built-in  
localization/i18n support.

If the application is localized, you could include the appropriate  
format in the localization file, and then you could use the “localize”  
helper:  
\<%=localize object.time\_attribute, :format =\> :custom\_or\_edited\_format  
%\>.

If the application is not localized, it is after all even easier/faster  
using the same technique.

Hope this helps.

Dav Y. wrote:

> I’ve spent all day digging through the rails api and postgres-pr on  
> this, I think it’s time to ask the list.
> 
> Postgres stores a Date in YYYY-MM-DD format. My users want the dates  
> in MM/DD/YYYY format.
> 
> Sure, I could explicitly convert it on the app level every place where  
> a date is displayed, but that seemed like a DRY violation.
> 
> I thought I’d be clever and simply redefine Date.to\_s with
> 
> class Date  
> def to\_s  
> strftime(’%m/%d/%Y’)  
> end  
> end

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [May 18, 2010, 9:40pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/19 "2010-05-18T21:40:22Z")

</div>

In Rails3 you can run:

Date::DATE\_FORMATS[:default] = “%m/%d/%Y”

skipping the ActiveSupport::CoreExtensions::…

see your installation of active support, eg:

activesupport-3.0.0.beta3/lib/active\_support/core\_ext/conversions.rb for  
more info.

Josh S. wrote:

> Dav Y. wrote:
> 
> > I’ve spent all day digging through the rails api and postgres-pr on  
> > this, I think it’s time to ask the list.
> > 
> > Postgres stores a Date in YYYY-MM-DD format. My users want the dates  
> > in MM/DD/YYYY format.
> > 
> > Sure, I could explicitly convert it on the app level every place where  
> > a date is displayed, but that seemed like a DRY violation.
> 
> There’s already a nice way to do this. ActiveSupport enhances Date#to\_s  
> to take a format parameter. Fire up script/console and look at the value  
> of this hash:  
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS
> 
> If you add an entry for :default, that will be used for all to\_s  
> conversions where you don’t specify a format. And you can use  
> some\_date.to\_s(:db) to output in the format for your database. If you  
> want to change or add formats, put something like this in your  
> environment.rb after the end of the Initializer block:
> 
> ActiveSupport::CoreExtensions::Time::Conversions::DATE\_FORMATS.merge!(  
> :default =\> ‘%m/%d/%Y’,  
> :date\_time12 =\> “%m/%d/%Y %I:%M%p”,  
> :date\_time24 =\> “%m/%d/%Y %H:%M”,  
> )
> 
> –josh  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Dav\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f1d935/32.png) [@Dav\_Y](https://www.ruby-forum.com/u/Dav_Y)\
**Post date:** [March 28, 2011, 3:59pm UTC](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779/20 "2011-03-28T15:59:41Z")

</div>

Use Rails I18n for this.

In config/locales/en.yml:

en:  
date:  
formats:  
default: “%m/%d/%Y”

In views:

\<%= l some\_model.date\_field %\>

[Next page](https://www.ruby-forum.com/t/changing-default-date-format-in-rails/54779.md?page=2)
