From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | zlatko(at)iskon(dot)hr |
Cc: | pgsql-sql(at)Postgresql(dot)org, pgsql-general(at)Postgresql(dot)org |
Subject: | Re: [SQL] Porting from mysql to psql (UNIX_TIMESTAMP()?) |
Date: | 2000-09-09 16:59:47 |
Message-ID: | 29365.968518787@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
Zlatko Calusic <zlatko(at)iskon(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Zeljko Trogrlic | 2000-09-09 17:44:04 | Re: Column name case conversion |
Previous Message | K Parker | 2000-09-09 16:35:05 | Re: Race conditions... |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-09-09 21:03:36 | Re: Creating an aggregate function |
Previous Message | Zlatko Calusic | 2000-09-09 12:30:35 | Re: Porting from mysql to psql (UNIX_TIMESTAMP()?) |