shanebonham
shanebonham

Reputation: 2279

Should Postgres timezone be changed from UTC?

I have a cron that runs a script in my rails app hourly looking for new transactions to run. Typically this only picks up new transactions set to start on the current day, until midnight UTC, when all the following day's transactions become due. My rails app is operating in Central Time, but Postgres is set to UTC. Since I'm using a scope with a where clause, and now() to compare the dates, transactions for the new day run in the early evening (in the US). Is there a downside to switching Postgres's timezone to Central Time? From what I can tell, it will record all timestamps in UTC regardless, but will run queries based on its timezone setting.

Upvotes: 1

Views: 961

Answers (1)

yfeldblum
yfeldblum

Reputation: 65445

You should always use UTC inside the application, and only perform conversions to other timezones at the edge of the application where necessary - such as in controllers or views.

In your query, perform some date manipulation on now() to translate it to the timezone you need.

Upvotes: 1

Related Questions