Date conversion from rails 2.3 to 3.2 in ActiveRecord


I am upgrading from rails 2.3 to 3.2 and I am have trouble with Date conversion.

In rails 2.3 the date conversion default format was mm/dd/yyyy and when I assigned a string in this format to a active_record model it converts the date correctly. for e.g.

I Have a user object(active_record object) and

In rails 2.3

user.registered_on = "10/03/2013" #=> Oct 3, 2013

But same thing in rails 3.2

user.registered_on = "10/03/2013" #=> March 10, 2013

How to fix this?

I have tried setting Date::DATE_FORMATS[:default] = '%m/%d/%Y' in one of the initializers file, but this does not do any good.

I have even the locales set for date, but that does not work as well.

One perfect way to reproduce this problem is:

  1. Create two apps, one in rails 2.3.x version and other in rails 3.2.x version.

  2. Create one model in each of the application with at-least one datetime field.

  3. Create and migrate the database for both the applications.

  4. Go to rails console from your terminal in each of the application.

  5. Create a active_record model object and assign this "10/3/2013" string to the datetime field and see the result both are different dates.

I just need a solution, how to fix this date or datetime conversion and make it same as rails 2.3

gem "american_date" solved this problem.