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-Koser
http://www.marnen.org
[email protected]

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to