shabda
shabda

Reputation: 1758

Convert datetime to UTC before storing in DB?

I have an app which will work in multiple timezones. I need the app to be able to say "Do this at 10 PM, 12 April, 2015, in the America/New York timezone and repeat every 30 days." (And similar).

If I get a datetime from the user in PST, should I be storing the datetime in DB after converting to UTC?

Pros: Easier to manage, every datetime in DB is in UTC. Cons: Can not take DST in account. (I think).

Upvotes: 0

Views: 288

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599560

Yes, you should store everything in your db in UTC.

I don't know why you say you won't be able to cope with DST. On the contrary, any good timezone library - such as pytz - is quite capable of translating UTC to the correct time in any timezone, taking DST into account.

Upvotes: 1

FlogFR
FlogFR

Reputation: 779

You mean UTC?

The database should handle all the logic about the time / timezone. You need to provide the right timezone to the database, then the database store it and provide it to the client for the timezone requested. For example the types in postgresql: here

What's your database?

Upvotes: 1

Related Questions