Skip site navigation (1) Skip section navigation (2)

Re: epoch to timestamp

From: David Fetter <david(at)fetter(dot)org>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: epoch to timestamp
Date: 2003-08-20 19:09:16
Message-ID: 20030820190916.GE14335@fetter.org (view raw or flat)
Thread:
Lists: sfpug
On Wed, Aug 20, 2003 at 10:51:01AM -0700, elein wrote:
> Someone tell me the easier, softer way to convert an epoch into a
> timestamp.

> This is the ugly way:
> select ('1/1/1970'::timestamp + '968190450 seconds')::timestamp;

Similar guts below...

On hackers, Tom Lane proposed a function that does this using Pl/PgSQL
like this:

CREATE OR REPLACE FUNCTION epoch_to_timestamp (FLOAT8)
    RETURNS timestampz AS '
BEGIN
    RETURN ''epoch''::timestamptz + $1 * ''1 second''::interval;
END;
' LANGUAGE 'plpgsql';

Despite the fact that it's (in hindsight) trivial to do, I'm still
lobbying for making this a built-in function.  Any pointers on how to
do this in C & roll it into the tree?

Cheers,
D
-- 
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100    cell: +1 415 235 3778

In response to

Responses

sfpug by date

Next:From: eleinDate: 2003-08-20 20:46:00
Subject: Re: epoch to timestamp
Previous:From: eleinDate: 2003-08-20 17:51:01
Subject: epoch to timestamp

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group