Hey, Thanks for the reply, I could easily write some code to discard the time field, which is what I'll probably do now but I'd just like to know how rails is doing this, I guess is should go about downloading the rails source and grok it myself.
I'm in GMT but using daylight savings. I guess if I just reset the time members of the DateTime object its returning to me I'm relatively insulated from errors if this translation changes in a future release. Thanks Barry On Oct 13, 7:20 pm, Marnen Laibow-Koser <li...@ruby-forum.com> wrote: > voidstar wrote in post #949920: > > > > > > > I currently have a model that simply contains one datetime field: > > > class CreateElectricityReadings < ActiveRecord::Migration > > def self.up > > create_table :clocks do |t| > > t.datetime :time_keeper > > t.timestamps > > end > > end > > > def self.down > > drop_table :clocks > > end > > end > > > If I enter the date string "13/10/2010" into this field its showing up > > in the controller as params[:clock][:time_keeper] "2010-10-13 23:00:00 > > UTC". > > Then you just need to call to_s on the date with the format you want. > Do this in the controller or the view: it's just like any other > presentation issue. Dates are not stored as strings in the DB. > > > I've tried overloading > > ActiveRecord::ConnectionAdapters::Column string_to_date(string) and > > ActiveRecord::ConnectionAdapters::Column string_to_time(string) but > > these seems to get hit when an object is saved not between the form > > submitting and the controller receiving the params object. Where is > > the mysterious 23:00:00 hours coming from? > > If I had to guess, I'd guess that you're in UTC+1 (Central European > Time). So perhaps it's storing the time as 0:00 local time, then > converting to UTC. But I could be wrong. > > > Can anyone point me to a > > good piece of reference reading for how dates and times work in rails > > land? > > You're overthinking it. Rails does some conversion when the form is > submitted to convert three form fields (day, month, year) into a Date > object for the DB, and then saves it to a date or datetime field in the > DB. In this case, you specified a datetime field in your migration, so > when Rails retrieves the record, it puts the value into a DateTime > object. If you don't want the time, don't use a datetime field in the > DB -- or just ignore the time. > > > > > Thanks > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > > -- > Posted viahttp://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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.