I''m going nuts over this incidence in my code: I have this class AdsSources < ActiveRecord::Base and one of it''s fields is a date, but when I update this field and read it again, I always get the same wrong date like this: @a = AdsSources.find :first @a.last_time_polled = Time.now; @a.save! I don''t get any Exceptions from this operation and it doesn''t matter if I use a different method like update_attributes, the result will be the same. Now, and this can be as soon as the following line in my code, I read this value like this: @a.last_time_polled And no matter when or how I updated this field the last time, I always get the same date: Sat Jan 01 22:43:26 +0100 2000 January 1st 2000. Could someone point me a reason for this? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 28 Aug 2008, at 21:57, Abel wrote:> > And no matter when or how I updated this field the last time, I always > get the same date: > > Sat Jan 01 22:43:26 +0100 2000 >> January 1st 2000. Could someone point me a reason for this? Thanks.What''s in the database ? 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-/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 -~----------~----~----~----~------~----~------~--~---
Use a :datetime field type instead of plain :date. I''m supposing thats the data type you have in your migration. Or if the date is not important, you can go with a pure :time approach. On Aug 28, 3:57 pm, Abel <abel.tam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m going nuts over this incidence in my code: I have this class > AdsSources < ActiveRecord::Base and one of it''s fields is a date, but > when I update this field and read it again, I always get the same > wrong date like this: > > @a = AdsSources.find :first > @a.last_time_polled = Time.now; > @a.save! > > I don''t get any Exceptions from this operation and it doesn''t matter > if I use a different method like update_attributes, the result will be > the same. Now, and this can be as soon as the following line in my > code, I read this value like this: > > @a.last_time_polled > > And no matter when or how I updated this field the last time, I always > get the same date: > > Sat Jan 01 22:43:26 +0100 2000 > > January 1st 2000. Could someone point me a reason for this? Thanks.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your replies, guys. I checked the content in the database and found that only the time of the day was being stored, so I changed the type of the column to ''timestamp'' and it''s working properly now. On Aug 29, 4:28 am, Pozole <poz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Use a :datetime field type instead of plain :date. I''m supposing thats > the data type you have in your migration. > Or if the date is not important, you can go with a pure :time > approach. > > On Aug 28, 3:57 pm, Abel <abel.tam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m going nuts over this incidence in my code: I have this class > > AdsSources < ActiveRecord::Base and one of it''s fields is a date, but > > when I update this field and read it again, I always get the same > > wrong date like this: > > > @a = AdsSources.find :first > > @a.last_time_polled = Time.now; > > @a.save! > > > I don''t get any Exceptions from this operation and it doesn''t matter > > if I use a different method like update_attributes, the result will be > > the same. Now, and this can be as soon as the following line in my > > code, I read this value like this: > > > @a.last_time_polled > > > And no matter when or how I updated this field the last time, I always > > get the same date: > > > Sat Jan 01 22:43:26 +0100 2000 > > > January 1st 2000. Could someone point me a reason for this? Thanks.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---