Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5L9XJa67946 for ; Thu, 21 Jun 2001 05:33:20 -0400 (EDT) (envelope-from dev@archonet.com) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 2.12 #1) id 15D0r5-0006se-0V; Thu, 21 Jun 2001 10:34:28 +0100 Received: from client (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id 78FE613A71; Thu, 21 Jun 2001 10:11:20 +0100 (BST) Message-ID: <009c01c0fa32$21fb4cc0$1001a8c0@archonet.com> From: "Richard Huxton" To: "pgsql" , "Najm Hashmi" Cc: "Tom Lane" References: <3B2F73BA.8EBA2FD1@flipr.com> Subject: Re: Extracting date from epoche Date: Thu, 21 Jun 2001 10:11:17 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200106/325 X-Sequence-Number: 3612 ----- Original Message ----- From: "Najm Hashmi" To: "pgsql" Sent: Tuesday, June 19, 2001 4:46 PM Subject: [SQL] Extracting date from epoche > Hi I have some data that is supose to be a date but in ecpoche > format. How can I reonvert it to data format. > Thanks in advance for help. > Regards, Something like: select '1970-01-01 00:00:00+00'::timestamp + (3600::text || ' seconds')::interval; should work (3600 is your offset, the 1970 assumes std unix epoch start). Keep an eye on timezone issues. Example: richardh=> select 'epoch'::date + (3600::text || ' seconds')::interval; ?column? ------------------------ 1970-01-01 01:00:00+01 (1 row) richardh=> select '1970-01-01 00:00:00+00'::timestamp + (3600::text || ' seconds')::interval; ?column? ------------------------ 1970-01-01 02:00:00+01 (1 row) The difference is because I am currently in timezone +01 and 'epoch' seems to assume my timezone. In the second example I explicitly set the timezone. Tom - I thought 'epoch'::timestamp should work too - good reason, or just One Of Those Things (tm)? - Richard Huxton