Re: convert in GMT time zone without summer time

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: convert in GMT time zone without summer time
Дата
Msg-id ioc0gr$53p$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на convert in GMT time zone without summer time  (LaraK <indarija@gmx.net>)
Ответы Re: convert in GMT time zone without summer time
Список pgsql-sql
On 2011-04-15, LaraK <indarija@gmx.net> wrote:
> Hello,
>
> I want write a function that converts a timestamp with time zone to the UTC
> zone. But it should all be stored in the winter time.
>
> For example, it must now, in the summer, the German time back by 2 hours and
> in the winter time only 1 hour. But it expects only back one hour.
>
> Is there a function or a specific time zone?

if I undestand your goal correctly you want to subtract the daylight
savings offset from the given timezone if daylight-savings is in use
in the current time locale.

you can detect daylight-savings by setting testing the timezone offset
at 3 month intervals ( timestamp, timestamp+3months timestamp-3months,
timestamp+6months, timestamp-6months)

the one(s) of them with the least (most negative) offset from UTC will
represent non daylight-saving time.

if your given time has a different offset it's daylight saving time,
add the difference.
calling:
> [CODE]
> SELECT                                    
> to_char(CONVERT_TO_UTC(to_timestamp('2011-03-22 14:17:00', 'YYYY-MM-DD
> hh24:MI:SS'), 'CET'), 'yyyy-mm-dd hh24:MI:SS') AS winter,
> to_char(CONVERT_TO_UTC(to_timestamp('2011-04-22 14:17:00', 'YYYY-MM-DD
> hh24:MI:SS'), 'CET'), 'yyyy-mm-dd hh24:MI:SS') AS summer
> [/CODE]
>
> must come out:
> [CODE]
> WINTER                | SUMMER
> --------------------+-------------------------
> 2011-03-22 13:17:00 | 2011-04-22 12:17:00
> [/CODE]

that test case is ambiguous your inputs are timespamptz but 
have an unspecified timezone (and so get the zone appropriate to 
your time locale). I'm assuming your time locale is "Europe/Berlin" 
and you really mean the following:

SELECT to_char(CONVERT_TO_UTC( '2011-03-22 14:17:00+01'::timestamptz
,'CET'),'yyyy-mm-dd hh24:MI:SS') AS winter, to_char(CONVERT_TO_UTC(
'2011-04-22 14:17:00+02'::timestamptz ,'CET'),'yyyy-mm-dd hh24:MI:SS')
AS summer;

CREATE OR REPLACE FUNCTION  CONVERT_TO_UTC ( timestamptz,  text) returns timestamp as  $$ SELECT $1 at time zone 'UTC';
$$ language sql;
 
In that this function does not use the second parameter it may not be
what you want, on the other hand it's function matches it's name well.
what are you trying to do?

-- 
⚂⚃ 100% natural



В списке pgsql-sql по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: update with recursive query
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: Get id of a tuple using exception