pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kachun Lee <kachun@pathlink.com>
To: Colin Dick <cdick@mail.ocis.net>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Date fields and libpq....
Date: Fri, 26 Jun 1998 13:42:57 -0700
Message-ID: <3.0.1.32.19980626134257.006b5b70@rr.pathlink.com> (raw)
In-Reply-To: <Pine.LNX.3.96.980626132618.19665A-100000@ocis.ocis.net>
References: <35940090.3D748711@mail.ocis.net>

At 01:28 PM 6/26/98 -0700, you wrote:
>> Hi there,
>>     I am doing a query on a date field and would like the answer in
>> epoch time as apposed to a string.  I am using PQgetvalue(res,i,0) and
>> can successfully get the string date as a response.  Is it possible to
>> get an epoch result or do I have to write my own routine to parse the
>> string into the tm struct so I can use mktime to get the epoch.  The
>> latter solution seems quite a hassle and if anyone has a better
>> solution, please let me know.  Thanks have a good weekend.
>
>Ooops,
>	Sorry, the field discussed above is cast as an abstime field not a
>date...  If that makes a difference.  I have tried explicitly casting the
>result from PQgetvalue(res,i,0) as an 'unsigned long' but now seem to be
>getting the numerical value of the string instead of the epoch number
>which I am looking for.  Still looking for answers if anyone has 'em..
>Thanks again.
>
>--
>Colin Dick
>On Call Internet Services
>cdick@mail.ocis.net

I think you may want to change your query to:

   select date_part(datetime(abst_att), 'epoch') ....

In addition, unless you were using BINARY cursor, you will need to do
something like:

  time_t t = atol(PQgetvalue(res, i, 0));



view thread (7+ messages)  latest in thread

Message-ID: <3.0.1.32.19980626134257.006b5b70@rr.pathlink.com>
Permalink:  ../3.0.1.32.19980626134257.006b5b70@rr.pathlink.com/
Also on:    postgresql.org/message-id/3.0.1.32.19980626134257.006b5b70@rr.pathlink.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: kachun@pathlink.com, cdick@mail.ocis.net
  Subject: Re: [SQL] Date fields and libpq....
  In-Reply-To: <3.0.1.32.19980626134257.006b5b70@rr.pathlink.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox