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