Re: Extracting date from epoche

From: "Richard Huxton" <dev(at)archonet(dot)com>
To: "pgsql" <pgsql-sql(at)postgresql(dot)org>, "Najm Hashmi" <najm(at)flipr(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Extracting date from epoche
Date: 2001-06-21 09:11:17
Message-ID: 009c01c0fa32$21fb4cc0$1001a8c0@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


----- Original Message -----
From: "Najm Hashmi" <najm(at)flipr(dot)com>
To: "pgsql" <pgsql-sql(at)postgresql(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2001-06-21 09:25:51 Re: pl/pgsql question (functions)
Previous Message Roelof Sondaar 2001-06-21 09:06:21 Re: set datestyle to European PROBLEM