We are having a debate about the best way to store a timestamp in postgres. Currently all time stamps are stored as +00 and we have a timezone associated with each client. We look up the timezone and convert the time that something happened which increases complexity as we need to do more joins and a more complex query.
Another method is connecting to Postgres and setting the timezone of the connection and it changes all the times to be that timezone.
My problem with this is that in ANZ there are 4-5 timezones. When we try and do our invoices we need to know what day certain transactions happened, and across three timezones there is no perfect solution.
I was thinking of including the timezone in the timestamp to make it easier - TIMESTAMP '1999-01-15 8:00:00 -8:00'
I was under the impression that this was best practice, but some people say this is a bad idea. We will have customers across ANZ that we need to do accurate invoices for, what is the best solution and most elegant?
Cheers Scott
time with timezone
is not recommended because it does not use a date to qualify the period that it is being saved in. Without this, daylight savings and other factors become impossible to calculate - hence why it is not recommended.timestamp with timezone
however is a different data type, which due to the existence of a date can save all its entries relative to UTC and adjust the time difference to the users preference. Ensure your server time is correct and all entries are set to the correct standard and your timings will be correct too. – Lucas Jan 31 at 1:10