Time Problem

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

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

Fred

On 18 Jun., 22:49, Frederick C. [email protected]
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)

Chris

On Jun 18, 10:05 pm, sigma [email protected] wrote:

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

On 18 Jun., 23:17, Frederick C. [email protected]
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