Hi all I''ve got following stupid problem: If I want to add a new record (with a DateTime-value) to database, there is allways the wrong time (2 h delay) saved. Here my code: user.userlogs.create({:date_session_started=>DateTime::now, :login_ip=>request.remote_ip()}) But: If I go to script/console and type "DateTime.now", the right time is returned. Also if I do a <%= DateTime.now %> in a view And if I connect to database via console and do a "SELECT NOW();"- request, also the right time is returned. Any idea? Greets sigma --~--~---------~--~----~------------~-------~--~----~ 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 18 Jun 2008, at 21:43, sigma wrote:> > Hi all > > I''ve got following stupid problem: > If I want to add a new record (with a DateTime-value) to database, > there is allways the wrong time (2 h delay) saved.Are you on rails 2.1, if so what is config.time_zone set to? in rails 2.1 if that is set rails will convert times to utc (and if I read your mail headers correctly your current time zone is UTC+2). There''s an overview of the time zone stuff at http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ Fred> > > Here my code: > user > .userlogs > .create > ({:date_session_started > =>DateTime::now, :login_ip=>request.remote_ip()}) > > But: > If I go to script/console and type "DateTime.now", the right time is > returned. > Also if I do a <%= DateTime.now %> in a view > And if I connect to database via console and do a "SELECT NOW();"- > request, also the right time is returned. > > Any idea? > > Greets > sigma > >--~--~---------~--~----~------------~-------~--~----~ 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 18 Jun., 22:49, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you on rails 2.1, if so what is config.time_zone set to? in rails > 2.1 if that is set rails will convert times to utc (and if I read your > mail headers correctly your current time zone is UTC+2). > There''s an overview of the time zone stuff athttp://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > > FredHi Thank you! Yes, I''m now on 2.1 ;-). I changed the config.time_zone to "Bern" (I''m from Switzerland). But nothing changed. (I also rebooted the mongrel- server) Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jun 18, 10:05 pm, sigma <christoph.thom...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 Jun., 22:49, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Are you on rails 2.1, if so what is config.time_zone set to? in rails > > 2.1 if that is set rails will convert times to utc (and if I read your > > mail headers correctly your current time zone is UTC+2). > > There''s an overview of the time zone stuff athttp://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > > > Fred > > Hi > Thank you! > > Yes, I''m now on 2.1 ;-). I changed the config.time_zone to "Bern" (I''m > from Switzerland). But nothing changed. (I also rebooted the mongrel- > server) >Does it make a difference if you use Time.now rather than DateTime.now ? What should happen is that some_object.date_session_started gives you the time in your local timezone, but the row in the database stores the utc time. When you say the date is stored incorrectly what are you comparing? (what you get when you evaluate some_object.date_session_started, what the mysql/psql/etc database client shows, something else ... ?) 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 18 Jun., 23:17, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What should happen is that some_object.date_session_started gives you > the time in your local timezone, but the row in the database stores > the utc time.Oops, sorry! This was the problem! I''m new in rails 2.1 and didn''t know that time is always stored in UTC Thank you for your help! Greets Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---