Re: Unixtime (epoch) into timestamp?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ericson Smith <eric(at)did-it(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unixtime (epoch) into timestamp?
Date: 2002-09-26 15:07:58
Message-ID: 4331.1033052878@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ericson Smith <eric(at)did-it(dot)com> writes:
> We mostly use unix times in our system because of the kind of
> applications that we have. Now we need to convert that into a timestamp.

The officially supported conversion methods are like this:

test72=# select extract(epoch from now());
date_part
------------------
1033052570.73262
(1 row)

test72=# select 'epoch'::timestamptz + interval '1033052570.73262 seconds';
?column?
------------------------------
2002-09-26 11:02:50.73262-04
(1 row)

But I tend to cheat on the latter. You can cast from int4 to abstime,
and the latter is really a time_t, so:

test72=# select 1033052570::int4::abstime;
abstime
------------------------
2002-09-26 11:02:50-04
(1 row)

And of course you can cast from abstime to timestamp. This will
probably break in 2038 ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2002-09-26 15:12:49 Re: Performance while loading data and indexing
Previous Message Denis Perchine 2002-09-26 15:04:41 Re: [HACKERS] Performance while loading data and indexing