Set the default date format for your Rails application

(Apologies to who I nicked this from – I can’t remember which book or blog post I found this)

The default string format for Dates is the ‘Database’ format which looks like this: => "2008-09-24" 

So, this means if you have dates in your views they’ll default to that unless you force the format.

It’s really easy to set the default format though! Bung something like this in your environment.rb:

:default => '%d %B %Y' )  

Where :default is the format you want to set. Now your dates will automatically default to a nice format! => "24 September 2008" 

You can do the same with the time format:

:default => '%d %B %Y'

Subscribe via RSS

Back to all blog posts