From: Michael Fuhr <mike@fuhr.org>
To: Norman Yamada <nyamada@millburncorp.com>
Cc: pgsql-interfaces@postgresql.org, Yasser El-Zein <yelzein@millburncorp.com>
Subject: Re: getting julian number from date in libpq
Date: Thu, 8 Sep 2005 13:37:43 -0600
Message-ID: <20050908193743.GA83658@winnie.fuhr.org> (raw)
In-Reply-To: <7D1583CD-3DEC-4F01-BF07-6599B7AEF38B@millburncorp.com>
References: <7D1583CD-3DEC-4F01-BF07-6599B7AEF38B@millburncorp.com>
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
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-interfaces@postgresql.org
Cc: mike@fuhr.org, nyamada@millburncorp.com, yelzein@millburncorp.com
Subject: Re: getting julian number from date in libpq
In-Reply-To: <20050908193743.GA83658@winnie.fuhr.org>
* 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