Paul Rubel
2010-Mar-08 14:47 UTC
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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Mar-08 18:41 UTC
Re: calling save changes a date field in my model instance to 2000
On Mar 8, 2:47 pm, Paul Rubel <pru...-A08e6c8yq/Q@public.gmane.org> wrote:> 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 >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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paul Rubel
2010-Mar-08 20:09 UTC
Re: Re: calling save changes a date field in my model instance to 2000
Frederick Cheung writes: > > > On Mar 8, 2:47 pm, Paul Rubel <pru...-A08e6c8yq/Q@public.gmane.org> wrote: > > 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.