| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Rasmus Resen Amossen <spunk(at)rhk(dot)dk> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: php, time and postgresql | 
| Date: | 2001-01-12 22:08:11 | 
| Message-ID: | 21717.979337291@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Rasmus Resen Amossen <spunk(at)rhk(dot)dk> writes:
> I want to save some time information in postgresql with php. What is the
> datatype in postgresql coresponding to the mktime()-unixtime function in
> php (creates a time in the format "979333398" eg.)?
You can coerce an integer representing a Unix timestamp to abstime,
and thence to any other datetime datatype you might want to use.
play=> select now()::abstime::integer;
 ?column?
-----------
 979337141
(1 row)
play=> select 979337141::integer::abstime;
        ?column?
------------------------
 2001-01-12 17:05:41-05
(1 row)
The "official" way to get from a datetime type to a Unix timestamp is
date_part('epoch', timevalue):
play=> select date_part('epoch', now());
 date_part
-----------
 979337212
(1 row)
but I don't know of any easy way to go in the other direction except by
casting to abstime.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2001-01-12 22:09:50 | Re: [HACKERS] problems with pg_geqo | 
| Previous Message | Alfred Perlstein | 2001-01-12 22:06:12 | Re: FreeBSDers paying attention? (was Re: exit status 26) |