A
A
Anton Ivanov2015-07-07 01:01:35
Ruby on Rails
Anton Ivanov, 2015-07-07 01:01:35

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_atand updated_atwith 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)

Is this correct, and isn't there some better way to fetch by created_at and use the time zone?
In past php projects, similar fields were created with the "timestamp with time zone" type and the selections did not require additional gestures (provided that a request was made when connecting to the database ). set timezone to ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mr Freeman, 2015-07-07
@vladamir

Also interesting, see the article , it might help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question