From: Richard Huxton <dev@archonet.com>
To: pgsql <pgsql-sql@postgresql.org>
To: Najm Hashmi <najm@flipr.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: Extracting date from epoche
Date: Thu, 21 Jun 2001 10:11:17 +0100
Message-ID: <009c01c0fa32$21fb4cc0$1001a8c0@archonet.com> (raw)
References: <3B2F73BA.8EBA2FD1@flipr.com>
----- Original Message -----
From: "Najm Hashmi" <najm@flipr.com>
To: "pgsql" <pgsql-sql@postgresql.org>
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
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-sql@postgresql.org
Cc: dev@archonet.com, najm@flipr.com, tgl@sss.pgh.pa.us
Subject: Re: Extracting date from epoche
In-Reply-To: <009c01c0fa32$21fb4cc0$1001a8c0@archonet.com>
References: <3B2F73BA.8EBA2FD1@flipr.com> <009c01c0fa32$21fb4cc0$1001a8c0@archonet.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