calling save changes a date field in my model instance to 2000

Hi,

I'm having a problem with dates (laugh if you must :).

$ rails --version Rails 2.3.5 $ ruby --version ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]

I have a bunch of data in a text file that I'd like to place in my DB but am ending up with odd results when I save the data.

Here's my model:

    class CreateWaits < ActiveRecord::Migration       def self.up         create_table :waits do |t|           t.string :location           t.integer :reg_wait_min           t.integer :lic_wait_min           t.time :collection_time #This is the troublesome one                t.timestamps         end       end

Here's an interaction from the console. I make a new Wait and give it a collection_time of Time.now. The resulting objects has a collection_time that looks right, March, 2010. At this point I call save and then search for the newly inserted data. It comes back with a collection_time in 2000. Any ideas what's going on? I'm new to rails so any advice will be greatly appreciated.

w = Wait.new(:location => "Arl",

                :reg_wait_min => 13,                 :lic_wait_min => 223,                 :collection_time => Time.now())

=> #<Wait id: nil, location: "Arl",      reg_wait_min: 13, lic_wait_min: 223,      collection_time: "2010-03-08 09:20:40", #HERE      created_at: nil, updated_at: nil>

w.save

=> true

Wait.find(:all, :conditions => ["location = 'Arl'"])

=> [#<Wait id: 2983, location: "Arl", reg_wait_min: 13,       lic_wait_min: 223,       collection_time: "2000-01-01 09:20:40", ## HUH?       created_at: "2010-03-08 14:20:55", updated_at: "2010-03-08 14:20:55">]

At this point w has also been updated to have the 2000 date.

    thanks much for your help,     Paul

it's because you've asked for a time column (which means that only the time of day component is saved, the date is ignored). If you want date & time make your column be a datetime

Fred

Frederick Cheung writes: > > > > Hi,

<snip>

> > I have a bunch of data in a text file that I'd like to place in my > > DB but am ending up with odd results when I save the data. > > > > Here's my model: > > > > class CreateWaits < ActiveRecord::Migration > > def self.up > > create_table :waits do |t| > > t.string :location > > t.integer :reg_wait_min > > t.integer :lic_wait_min > > t.time :collection_time #This is the troublesome one > > > it's because you've asked for a time column (which means that only the > time of day component is saved, the date is ignored). If you want date > & time make your column be a datetime

Ah ha. That makes sense.

   Thanks much,    Paul