Re: epoch from date field

From: Thomas Lockhart <lockhart(at)fourpalms(dot)org>
To: missive(at)hotmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: epoch from date field
Date: 2002-07-04 13:57:52
Message-ID: 3D245460.8E17B0A3@fourpalms.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > select extract(epoch from date(map_date)) from datemaps;
> > For a date: 2002-07-04
> > it returns 1025740800
> > which apparently translates to today (7/3) at 5pm. Is this right?
> > Shouldn't it return the epoch for midnight on 7/4?
> Hmm. Just a guess, but could this be a time zone thing?

The epoch *is* for midnight on 2002-07-04 in the UTC time zone, much
like you would expect from a Unix system call to time(). Note that when
called for an input of 1970-01-01 you will get a value of zero (which is
a clue that you do not have a time zone issue) and when called for a
value of 1970-01-02 you get a value of 86400 (the number of seconds in a
day).

More evidence and test cases are included below. hth

- Thomas

thomas=# select extract(epoch from date '2002-07-04');
date_part
------------
1025740800
(1 row)

thomas=# select extract(epoch from date '1970-01-02');
date_part
-----------
86400
(1 row)

thomas=# select extract(epoch from date '2002-07-04') / 86400.0;
?column?
----------
11872

- Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Janning Vygen 2002-07-04 14:01:56 plpgsql: PERFORM SELECT id INTO TEMP TABLE ..
Previous Message Frank Joerdens 2002-07-04 13:47:44 Re: uploading texts