Re: Obtaining the Julian Day from a date - Mailing list pgsql-general

From Tom Lane
Subject Re: Obtaining the Julian Day from a date
Date
Msg-id 10750.1094916827@sss.pgh.pa.us
Whole thread Raw
In response to Re: Obtaining the Julian Day from a date  ("Karl O. Pinc" <kop@meme.com>)
Responses Re: Obtaining the Julian Day from a date  ("Karl O. Pinc" <kop@meme.com>)
List pgsql-general
"Karl O. Pinc" <kop@meme.com> writes:
> On 2004.09.10 20:32 Bruno Wolff III wrote:
>> If you keep your data in a date field you can get the Julian day
>> by subtracting the appropiate date. You can then do mod on this
>> difference.

> I've been doing:
> CAST (to_char(date, 'J') AS INT)
> but your way seems faster.  Is it?

Date subtraction is extremely fast (it's really the same as integer
subtraction), so yes I'd expect it to beat the pants off doing to_char
and then conversion back to integer.

Another advantage is that you can equally easily adopt *any* base date,
it doesn't have to be Julian day 0.  This would let you shift between
say Monday and Sunday as start-of-the-week without extra logic.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: What is the postgres version of mysql's "ON DUPLICATE KEY"
Next
From: Josué Maldonado
Date:
Subject: pass an array as parameter to a function