Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Date Format in Rails (Need it to be ddmmyyyy)

I've been working with a rails form all day and I was just randomly testing it and tried the date 25/12/2009 and it came up with a huge error.

It was at this point I realised that rails is set to american date mode (mm/dd/yyyy) instead of the UK style: dd/mm/yyyy.

How can I set rails to automatically deal with all dates in dd/mm/yyyy format?

like image 629
Chris Avatar asked Oct 22 '09 22:10

Chris


1 Answers

If you're using @Chris Ballance's solution note that Rails now modifies the Date class directly so you'll get an uninitialized constant ActiveSupport error with the solution.

See: uninitialized constant ActiveSupport::CoreExtensions

The updated argument:

my_date_formats = { :default => '%d/%m/%Y' } 
Time::DATE_FORMATS.merge!(my_date_formats) 
Date::DATE_FORMATS.merge!(my_date_formats)
like image 72
vladiim Avatar answered Oct 06 '22 14:10

vladiim