I configured ActiveRecord in my environment.rb file to use UTC as follows: config.active_record.default_timezone = :utc I am using MySQL 5.0.x In a table, called comments, model Comment, there is a field called created_at as :datetime. I basically get two different time shown on the mysql console based on the two following commands: Comment.create # this will automatically set the time in :created_at Comment.create :created_at => Time.now The time difference is 3 hours (apparently the difference of my time zone to UTC). If is set :utc conversion off in my environment, everything works fine. I even set the MySQL time conversion tables, but still won''t work. Is there a way to set MySQL time zone correctly, and how? What am I doing wrong? Greetings, Juergen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Time#now will return the current time for your timezone, and it won''t get converted into UTC when you save it to the database. You need to qualify it with #utc: Comment.create :created_at => Time.now.utc On Apr 14, 7:45 am, "ginger72" <jfesslme...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I configured ActiveRecord in my environment.rb file to use UTC as > follows: > > config.active_record.default_timezone = :utc > > I am using MySQL 5.0.x > > In a table, called comments, model Comment, there is a field called > created_at as :datetime. I basically get two different time shown on > the mysql console based on the two following commands: > > Comment.create # this will automatically set the time in :created_at > Comment.create :created_at => Time.now > > The time difference is 3 hours (apparently the difference of my time > zone to UTC). If is set :utc conversion off in my environment, > everything works fine. I even set the MySQL time conversion tables, > but still won''t work. Is there a way to set MySQL time zone correctly, > and how? > > What am I doing wrong? > Greetings, > Juergen--~--~---------~--~----~------------~-------~--~----~ 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 4/15/07, eden li <eden.li-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Time#now will return the current time for your timezone, and it won''t > get converted into UTC when you save it to the database. You need to > qualify it with #utc:I blogged about the TzTime plugin and how I use it in Lighthouse: http://activereload.net/2007/4/13/dealing-with-timezones For once my timezones work, and I don''t have to manage that stuff manually. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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-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 -~----------~----~----~----~------~----~------~--~---