Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

620
Views
Grafana/Postgresql: how to convert date stored in UTC to local timezone

I have a date stored in postgres db, e.g. 2019-09-03 15:30:03. Timezone of postgres is UTC.

When Grafana gets the date, it is 2020-09-03T15:30:03.000000Z. If I now run date_trunc('day', 2020-09-03T15:30:03.000000Z), I get 2020-09-03T00:00:00.000000Z. But, I want midnight in my local timezone.

  1. How do I get the local timezone (offset) in postgres or grafana?
  2. Could I get the timezone in military style, instead of "Z" for UTC "B"?
  3. Or can I somehow subtract the offset of the local timezone to get a UTC date corresponding to midnight local time?

Thanks in advance Michael

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Get the local timezone (offset):

select to_char(now(), 'OF');
-- result '+03' for EEST

Get UTC time corresponding to midnight local time:

select date_trunc('DAY', now()) at time zone 'UTC';
-- result '2020-06-05 21:00:00.0' for 13:30 EEST on 2020-06-06

Convert UTC time to local timezone time:

select now();
-- Local time is 2020-06-06 13:43:27.482463
select (now() at time zone 'UTC');
-- UTC time is 2020-06-06 10:43:27.482463

select '2020-06-06 10:43:27.482463UTC'::timestamp with time zone; 
-- UTC time converted to local time is 2020-06-06 13:43:27.482463

Hope that this helps.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!