How to change ActiveRecord date format conversion

I am using custom control for entering a date on the form. My date
format is dd.mm.yyyy and this is also what the control returns to
program. But ActiveRecord expects date to be formated as mm.dd.yyyy and
thus saves wrong value to database.

I have implemented method which corrects date fields prior to save to
database, but it is clumsy. There must be a solution to configure
ActiveRecord so it will interpret my date string corectly. It does so
for strings formated like yyyymmdd.

by
TheR

On Jun 4, 3:49 am, Damjan R. [email protected]
wrote:

I am using custom control for entering a date on the form. My date
format is dd.mm.yyyy and this is also what the control returns to
program. But ActiveRecord expects date to be formated as mm.dd.yyyy and
thus saves wrong value to database.

I have implemented method which corrects date fields prior to save to
database, but it is clumsy. There must be a solution to configure
ActiveRecord so it will interpret my date string corectly. It does so
for strings formated like yyyymmdd.

Override the date= method in the model (change date to whatever
attribute is the date you are trying to fix), and use ParseDate to
turn the string data into a date object. This should probably be in
the controller your form is posting to, though, and not Active
Record. If you pass in a valid Time object, AR will put it in the
correct DB format.

also have a look at plugin
validates_date_time
By default, it allows european format entry and displays dates in the
universal format yyyy-mm-dd

Tonypm