Re: timestamp? - Mailing list pgsql-general

From Tom Lane
Subject Re: timestamp?
Date
Msg-id 140.972673291@sss.pgh.pa.us
Whole thread Raw
In response to timestamp?  (Igor Roboul <igor@raduga.dyndns.org>)
Responses Re: timestamp?  (Igor Roboul <igor@raduga.dyndns.org>)
List pgsql-general
Igor Roboul <igor@raduga.dyndns.org> writes:
> Let assume that we have relation R01(id integer,ts timestamp)
> Now I know that if I use PQgetvalue() for ts value, I'll get char*
> to nullterminated string. How can I get time_t value for ts in
> portable way (without parsing returned string)?

If you want to produce a time_t painlessly, the simplest way is not
to SELECT the raw timestamp, but rather date_part('epoch', timestamp).
This gives you back an integer number of seconds per Unix conventions,
which you just use atoi() on.  For example:

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

            regards, tom lane

pgsql-general by date:

Previous
From: Igor Roboul
Date:
Subject: timestamp?
Next
From: teg@redhat.com (Trond Eivind Glomsrød)
Date:
Subject: Re: 7.0 vs. 7.1 (was: latest version?)