Re: timestamp?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: igorr(at)crosswinds(dot)net
Cc: pgsql-general(at)hub(dot)org
Subject: Re: timestamp?
Date: 2000-10-27 19:01:31
Message-ID: 140.972673291@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Igor Roboul <igor(at)raduga(dot)dyndns(dot)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

In response to

  • timestamp? at 2000-10-27 15:49:28 from Igor Roboul

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2000-10-27 19:03:33 Re: [GENERAL] 7.0 vs. 7.1 (was: latest version?)
Previous Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2000-10-27 19:01:21 Re: 7.0 vs. 7.1 (was: latest version?)