From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Norman Yamada <nyamada(at)millburncorp(dot)com> |
Cc: | pgsql-interfaces(at)postgresql(dot)org, Yasser El-Zein <yelzein(at)millburncorp(dot)com> |
Subject: | Re: getting julian number from date in libpq |
Date: | 2005-09-08 19:37:43 |
Message-ID: | 20050908193743.GA83658@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
On Thu, Sep 08, 2005 at 02:12:33PM -0400, Norman Yamada wrote:
> We're trying to convert dates properly for R.
>
> R stores dates internally as integers, using Unix date style --
> starting date is January 1, 1970.
>
> Postgresql stores dates as Julian days, but using libpq, I don't see
> how to get out a date quickly as a julian day. If I use PQgetvalue,
> my date is automagically converted into whatever my DATESTYLE is at
> the time. How can I just get out the internal julian date?
In 7.4 and later you could use PQexecParams() to request binary
results; in earlier versions you could use a binary cursor. But
the result will be days since 1 Jan 2000, not 1 Jan 1970, so you'd
have to do a conversion; you'd also have to convert the binary value
from network byte order to host byte order. It might be easier to
use the date subtraction operator:
SELECT current_date - '1970-01-01';
?column?
----------
13034
(1 row)
--
Michael Fuhr
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-09-08 19:45:06 | Re: getting julian number from date in libpq |
Previous Message | Norman Yamada | 2005-09-08 18:12:33 | getting julian number from date in libpq |