Skip to content
Advertisement

PostgreSQL get results in current time zone

as said in the title I would like to have a query that returns the value of the time stamp in my current time zone (even according summer time!).

my_table is:

(Don’t ask me why I cannot put this table directly in markdown…prob cause the dates)

Now for example if I have to select the 24h corresponding to the entire day in my time zone at the moment my solution is:

As you can see there is a problems here:

  • I have to specify every time if I is CEST or CET (now is CEST here)
  • and then I have to add +02 at the end of the dates (or +01 in CET)

There is a way to avoid this conceptual repetition?? any suggestion even to improve the query is appreciated

the command SELECT version(); gives me back PostgreSQL 12.7

Advertisement

Answer

Set your session’s timezone appropriately.

What is your session timezone set to now?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement