Re: timezone difference in timestamp?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: meltedown <asdf(at)fake(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: timezone difference in timestamp?
Date: 2006-11-06 19:08:15
Message-ID: 28638.1162840095@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

meltedown <asdf(at)fake(dot)com> writes:
> Short version: I'm trying to turn a unix timestamp into a psql
> timestamp, but there is a 5 hour difference. Is this because of
> timezones ? Can I just subtract 5 hours to get the right value ?

> "select timestamp '1970-01-01' + interval '$startofday seconds' as
> timestamp"

If it really is a Unix timestamp --- ie, referenced to midnight GMT
1970-01-01 --- then you need to start with midnight GMT not midnight
local time as the basis. So,

select timestamp with time zone '1970-01-01 00:00 GMT' + interval ...

or better yet

select timestamp with time zone 'epoch' + interval ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Whidden 2006-11-06 19:14:20 Tsearch Index Size and GiST vs. GIN
Previous Message Josh Berkus 2006-11-06 18:58:14 Re: Need replacement booth member for USENIX Lisa