timestamp?

Started by Igor Roboulover 25 years ago3 messagesgeneral
Jump to latest
#1Igor Roboul
igor@raduga.dyndns.org

Hello,

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)?
Sorry, if my English is not very understandable :-)

--
Igor Roboul, Unix System Administrator & Programmer @ sanatorium "Raduga",
Sochi, Russia
http://www.brainbench.com/transcript.jsp?pid=304744

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Igor Roboul (#1)
Re: timestamp?

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

#3Igor Roboul
igor@raduga.dyndns.org
In reply to: Tom Lane (#2)
Re: timestamp?

On Fri, Oct 27, 2000 at 03:01:31PM -0400, Tom Lane wrote:

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());

Thanx

--
Igor Roboul, Unix System Administrator & Programmer @ sanatorium "Raduga",
Sochi, Russia
http://www.brainbench.com/transcript.jsp?pid=304744