pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Returning timestamp with timezone at specified timezone irrespective of client timezone
Date: Sun, 27 Sep 2020 18:13:09 -0500
Message-ID: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com> (raw)
In-Reply-To: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com>
References: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com>

On 9/27/20 4:16 PM, aNullValue (Drew Stemen) wrote:
> Hello,
>
> I've attempted to obtain help with this problem from several other places, 
> but numerous individuals recommended I ask this mailing list.
>
> What I need is for the ability to return a timestamp with timezone, using 
> the UTC offset that corresponds to a column-defined timezone, irrespective 
> of the client/session configured timezone.
>
> I have three columns in a table:
> Timezone: 'US/Eastern'
> Date: 2020-10-31
> Time: 08:00
>
> The output I'm able to find includes these possibilities:
> '2020-10-31 08:00:00'
> '2020-10-31 12:00:00+00'
>
> Whereas what I actually need is:
> '2020-10-31 08:00:00-05'
>
> Using the postgresql session-level timezone configuration won't work 
> because I need multiple timezones to be handled in a single set.
>
> Example code follows. I'm not using to_char in the examples as I likely 
> would in the production code, but I haven't found any way that it could be 
> helpful here regardless.
>
[snip]
>
> id |  timezone  | loc_date  | loc_time |         tswtz          |       tswotz
> ----+------------+------------+----------+------------------------+---------------------
>   7 | US/Central | 2020-10-31 | 08:00    | 2020-10-31 13:00:00+00 | 
> 2020-10-31 08:00:00
>   8 | US/Central | 2020-11-03 | 08:00    | 2020-11-03 14:00:00+00 | 
> 2020-11-03 08:00:00
>   5 | US/Eastern | 2020-10-31 | 08:00    | 2020-10-31 12:00:00+00 | 
> 2020-10-31 08:00:00
>   6 | US/Eastern | 2020-11-03 | 08:00    | 2020-11-03 13:00:00+00 | 
> 2020-11-03 08:00:00
> (4 rows)
>
> What I actually need is, in example id=7, '2020-10-31 08:00:00-05'.
>
> Is this even possible? Several people have proposed that I write a custom 
> function to do this on a per-row basis, which... I suppose I can do... I'm 
> just blown away that this isn't something that just works "out of the box".
>

Are you really asking what the TZ offset was on a specific date (Like DST or 
not)?

-- 
Angular momentum makes the world go 'round.

view thread (14+ messages)  latest in thread

Message-ID: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com>
Permalink:  ../6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com/
Also on:    postgresql.org/message-id/6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Returning timestamp with timezone at specified timezone irrespective of client timezone
  In-Reply-To: <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com>
  References: <3af9fdd2-b622-426a-8e1e-aeab1bee8493@www.fastmail.com> <6b269cb9-5572-acaa-de9c-fe1c705fed11@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox