From: Tobias Luetke Date: 2004-12-11T07:34:27+09:00 Subject: Re: Date manipulation in rails You could override the date= method of the model to store away the string which is assigned to the model in an instance variable so you can later validate it. This assumes that you get the date as a string through the parameters. Did you consider to use the date helpers of rails like date_select ? http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html On Sat, 11 Dec 2004 07:13:01 +0900, Johan Allard wrote: > Hi all, > > I live in australia in in Australia dates are written as DD/MM/YYYY. In > the database, the dates are stored as YYYY-MM-DD. I want to use the > before_validation function and check if #{(\d+)/(\d+)/(\d+)} and then > convert to the correct iso date format. > > The problem is that when the before_validation function kicks in, the > date variable is now a Date object. It is no longer a string, and it > has been formatted using the american MM/DD/YYYY format to YYYY-MM-DD. > Since it is a date object, it is not possible to check how the date was > formatted. > > Currently I run the check in the controller and to keep the model > intact it would be fantastic if there was a way of doing this in the > before_validation function (or similar) instead. > > Thank you > > //johan > > -- Tobi http://blog.leetsoft.com