I have a postgres database, that stores some accounting data.
The accounting data have a timestamp (with timezone).
I would like to aggregate/group the accounting data by date.
But the date should be in the user’s/requested timezone not UTC.
SELECT '2023-08-01'::timestamp AT TIME ZONE 'Europe/Berlin'; -- 2023-07-31 22:00:00+00
Outputs the correct UTC value for the timestamp,
but if I cast that to date then it returns the UTC date:
SELECT date('2023-08-01'::timestamp AT TIME ZONE 'Europe/Berlin'); -- 2023-07-31
Is there a way to output the date in Europe/Berlin time? (2023-08-01
)
2
Answers
Here’s how you can do it
In order to Group/Sum, use this approach
Hope this is what you are looking for.
Given a
timestamp with time zone
, you can get the current date in Germany at that time withYour example uses a
timestamp without time zone
, which may be the problem.