Re: getting julian number from date in libpq - Mailing list pgsql-interfaces

From Michael Fuhr
Subject Re: getting julian number from date in libpq
Date
Msg-id 20050908193743.GA83658@winnie.fuhr.org
Whole thread Raw
In response to getting julian number from date in libpq  (Norman Yamada <nyamada@millburncorp.com>)
Responses Re: getting julian number from date in libpq  (Norman Yamada <nyamada@millburncorp.com>)
List 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


pgsql-interfaces by date:

Previous
From: Norman Yamada
Date:
Subject: getting julian number from date in libpq
Next
From: Tom Lane
Date:
Subject: Re: getting julian number from date in libpq