Answer the question
In order to leave comments, you need to log in
What is the correct way to query created_at in Rails using the time zone?
Hello!
Rails - 4.1
Base - PostgreSQL
Each user can have their own time zone, which is set via Time.zone = user_time_zone
Rails creates created_at
and updated_at
with type. timestamp without time zone
If you make a selection using find methods and conditions, then everything works correctly. But if you make a selection through an sql query, then you have to write something like this:
where('table.created_at between ? and ?', Time.now.beginning_of_week.utc, Time.now.end_of_day.utc)
set timezone to ...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question