Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:17:02+00:00 2026-06-11T01:17:02+00:00

I am working with dates relative to the database server. In Oracle, to get

  • 0

I am working with dates relative to the database server.

In Oracle, to get the full timezone offset you would use something like the following:

select tz_offset(SESSIONTIMEZONE) from dual;

or

select tz_offset(DBTIMEZONE) from dual;

These would return, in my case (importantly it includes the sign)

-04:00

I was wondering what functionality exists in Postgres to get a result of the exact same format as the Oracle version above? I need to know the timezone offset of the server inclusive of the sign indicating it being behind or ahead of GMT/UTC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:17:03+00:00Added an answer on June 11, 2026 at 1:17 am

    For the time zone you can:

    SHOW timezone;
    

    or the equivalent:

    SELECT current_setting('TIMEZONE');
    

    but this can be in any format accepted by the server, so it may return UTC, 08:00, Australia/Victoria, or similar.

    Frustratingly, there appears to be no built-in function to report the time offset from UTC the client is using in hours and minutes, which seems kind of insane to me. You can get the offset by comparing the current time in UTC to the current time locally:

    SELECT age(current_timestamp AT TIME ZONE 'UTC', current_timestamp)`
    

    … but IMO it’s cleaner to extract the tz offset in seconds from the current_timestamp and convert to an interval:

    SELECT to_char(extract(timezone from current_timestamp) * INTERVAL '1' second, 'FMHH24:MM');
    

    That’ll match the desired result except that it doesn’t produce a leading zero, so -05:00 is just -5:00. Annoyingly it seems to be impossible to get to_char to produce a leading zero for hours, leaving me with the following ugly manual formatting:

    CREATE OR REPLACE FUNCTION oracle_style_tz() RETURNS text AS $$
    SELECT to_char(extract(timezone_hour FROM current_timestamp),'FM00')||':'||
           to_char(extract(timezone_minute FROM current_timestamp),'FM00');
    $$ LANGUAGE 'SQL' STABLE;
    

    Credit to Glenn for timezone_hour and timezone_minute instead of the hack I used earlier with extract(timezone from current_timestamp) * INTERVAL '1' second) and a CTE.

    If you don’t need the leading zero you can instead use:

    CREATE OR REPLACE FUNCTION oracle_style_tz() RETURNS text AS $$
    SELECT to_char(extract(timezone from current_timestamp) * INTERVAL '1' second, 'FMHH24:MM');
    $$ LANGUAGE 'SQL' STABLE;
    

    See also:

    • Local time zone offset in PostgreSQL
    • How to know a timezone of a timestamp in postgresql 8.3
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with an oracle legacy database. All the dates are saved in
I'm working with an existing database where all dates are stored as integers in
I am working with dhtmlxscheduler and I am sending dates to the django server
Working on an application where we would like the user to be able to
Im working on a database that store dates in a varchar(10) mysql field (so
I always get confused when working with dates in PHP and MySQL. I looked
working on a script, that calculates the difference between dates retrieved from an API.
I am working on ASP.net Webform application where i need to block certain dates
I'm working on a client's site, and he needs coupon expiration dates to change
I am working out the months, days, hours and minutes between two dates, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.