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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Clever Neologism
2008-Jun-04 14:16 UTC
Re: How to change ActiveRecord date format conversion
On Jun 4, 3:49 am, Damjan Rems <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---