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.
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 Mad Mimi Email Marketing
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 ... ?)