pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: zlatko@iskon.hr
Cc: pgsql-sql@Postgresql.org
Cc: pgsql-general@Postgresql.org
Subject: Re: [SQL] Porting from mysql to psql (UNIX_TIMESTAMP()?)
Date: Sat, 09 Sep 2000 12:59:47 -0400
Message-ID: <29365.968518787@sss.pgh.pa.us> (raw)
In-Reply-To: <874s3p3k1c.fsf@atlas.iskon.hr>
References: <874s3p3k1c.fsf@atlas.iskon.hr>

Zlatko Calusic <zlatko@iskon.hr> writes:
> Is there any similar functionality (returning unixish number of
> seconds since 1970 from the timestamp field) in PostgreSQL?

Sure.  You can use date_part, or cast to abstime and thence to integer:

regression=# select now();
          now
------------------------
 2000-09-09 12:55:50-04
(1 row)

regression=# select date_part('epoch',now());
 date_part
-----------
 968518563
(1 row)

regression=# select now()::abstime::int4;
 ?column?
-----------
 968518585
(1 row)

To go the other way (integer seconds to timestamp), use the cast
method in reverse:

regression=# select 968518585 :: int4 :: abstime :: timestamp;
        ?column?
------------------------
 2000-09-09 12:56:25-04
(1 row)

(there's probably a cleaner way to do this, but that works ...)

			regards, tom lane



view thread (4+ messages)

Message-ID: <29365.968518787@sss.pgh.pa.us>
Permalink:  ../29365.968518787@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29365.968518787@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, zlatko@iskon.hr, pgsql-general@Postgresql.org
  Subject: Re: [SQL] Porting from mysql to psql (UNIX_TIMESTAMP()?)
  In-Reply-To: <29365.968518787@sss.pgh.pa.us>
  References: <874s3p3k1c.fsf@atlas.iskon.hr> <29365.968518787@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox