Skip site navigation (1) Skip section navigation (2)

Re: getting julian number from date in libpq

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: (view raw, whole thread or download thread mbox)
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';
(1 row)

Michael Fuhr

In response to


pgsql-interfaces by date

Next:From: Tom LaneDate: 2005-09-08 19:45:06
Subject: Re: getting julian number from date in libpq
Previous:From: Norman YamadaDate: 2005-09-08 18:12:33
Subject: getting julian number from date in libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group