Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2E2D51337B2F for ; Sat, 16 Apr 2011 09:30:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 02271-02 for ; Sat, 16 Apr 2011 12:30:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 506531336FA7 for ; Sat, 16 Apr 2011 09:30:24 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QB4dq-0002ua-CN for pgsql-sql@postgresql.org; Sat, 16 Apr 2011 14:30:22 +0200 Received: from ip-118-90-133-108.xdsl.xnet.co.nz ([118.90.133.108]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 16 Apr 2011 14:30:22 +0200 Received: from jasen by ip-118-90-133-108.xdsl.xnet.co.nz with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 16 Apr 2011 14:30:22 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Jasen Betts Subject: Re: convert in GMT time zone without summer time Date: 16 Apr 2011 12:02:35 GMT Organization: Dis (not Dat) Organisation Lines: 62 Message-ID: References: <1302848430605-4304830.post@n5.nabble.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ip-118-90-133-108.xdsl.xnet.co.nz X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/24 X-Sequence-Number: 35271 On 2011-04-15, LaraK 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