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 8000203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:43:14+00:00 2026-06-04T15:43:14+00:00

My server is in Central Time. I would like to render timestamps using Eastern

  • 0

My server is in Central Time. I would like to render timestamps using Eastern time.

For instance, I would like to render 2012-05-29 15:00:00 as 2012-05-29 16:00:00 EDT.

How can I achieve it?

to_char('2012-05-29 15:00:00'::timestamptz at time zone 'EST5EDT', 'YYYY-MM-DD HH24:MI:SS TZ') gives 2012-05-29 16:00:00 (no zone).

to_char('2012-05-29 15:00:00'::timestamp at time zone 'EST5EDT', 'YYYY-MM-DD HH24:MI:SS TZ') gives 2012-05-29 14:00:00 CDT (wrong).

This one works, but it’s so ridiculously complicated there must be an easier way: replace(replace(to_char(('2012-05-29 15:00:00'::timestamptz at time zone 'EST5EDT')::timestamptz, 'YYYY-MM-DD HH24:MI:SS TZ'), 'CST', 'EST'), 'CDT', 'EDT')

  • 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-04T15:43:15+00:00Added an answer on June 4, 2026 at 3:43 pm

    The key is to switch the local timezone to the desired display timezone, for the duration of the transaction:

    begin;
    set local timezone to 'EST5EDT';
    select to_char('2012-05-29 15:00:00'::timestamp at time zone 'CDT',
      'YYYY-MM-DD HH24:MI:SS TZ');
    end;
    

    The result is:

    2012-05-29 16:00:00 EDT

    Note that with set [local] timezone it is required to use full time zone names instead of abbreviations (for instance, CST would not work). Look up in the pg_timezone_names view for valid choices.

    To use that method in a context similar to a to_char() call, I believe this function does the job:

    CREATE FUNCTION display_in_other_tz(
          in_t timestamptz,
          in_tzname text,
          in_fmt text) RETURNS text
    AS $$
    DECLARE
     v text;
     save_tz text;
    BEGIN
      SHOW timezone into save_tz;
      EXECUTE 'SET local timezone to ' || quote_literal(in_tzname);
      SELECT to_char(in_t, in_fmt) INTO v;
      EXECUTE 'SET local timezone to ' || quote_literal(save_tz);
      RETURN v;
    END;
    $$ language plpgsql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I can connect remote offices to a central
We are using EHCache with CF 8 to cache stuff on a central server
I'm using TortoiseGit on Windows XP. My team all use a central svn server
I am using Ruby on Rails 3 and I would like to handle user
Are there any known methods of finding peers without using a dedicated central server?
I'm building a multi-OS mirroring system which I would like to implement using a
The purpose of this code is to pull upgrade.zip from a central server, extract
I am developing a LAN-based database application. It involves a central server app to
First, by Remote I mean a central dedicated SQL Server on our Network. By
My company is working on a development project using SQL Server 2008 Express. The

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.