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

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

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

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

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