Re: date calculation - Mailing list pgsql-sql

From Tom Lane
Subject Re: date calculation
Date
Msg-id 6305.1061557010@sss.pgh.pa.us
Whole thread Raw
In response to Re: date calculation  (Tomasz Myrta <jasiek@klaster.net>)
List pgsql-sql
Tomasz Myrta <jasiek@klaster.net> writes:
> cast('1970-1-1' as timestamp)+cast(your_ticks || ' seconds' as interval)

> Does anyone know better way to cast it?

The above will probably give the wrong answer (off by your timezone
offset).  The reference point should be zero hour GMT, but the first
cast will give zero hour local time.  You should cast the reference
to timestamp with time zone (timestamptz) instead.

Also, I'd suggest using float-times-interval as a simpler and more
efficient way of forming the offset interval.  So:

select 'epoch'::timestamp with time zone + your_ticks * '1 second'::interval;
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: "SELECT IN" Still Broken in 7.4b
Next
From: Stephan Szabo
Date:
Subject: Re: Bug on parameter bigint in PL/PGSQL