I have a query that hits my database and it returns a column of dates. the output of this query looks something like this in psql:
Query:
SELECT (by_event.event_date AT TIME ZONE 'UTC')::DATE as event_date from events as by_event;
Output:
event_date
------------
2012-11-15
2012-11-16
2012-11-17
I run my SQL query in Rails with this:
results = ActiveRecord::Base.connection.execute(sql)
results.each do |result|
puts result.inspect
end
This unfortunately prints out:
[{\"event_date\"=>\"2012-11-16\"}, {...}]
All of the dates are one day ahead of what they should be!
Obviously this is timezone related, but I am not sure how to fix it. How do I get Rails to stop bumping up the date?
config/application.rb
check whatconfig.time_zone
is set to. If its not set, set it to your desired time zone and things should be fine.Time.zone = "EST"
andTime.zone = "UTC"
with no change in results. just before running the query.