Re: Setting week starting day

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Setting week starting day
Date: 2007-03-09 16:35:09
Message-ID: 877itqiddu.fsf@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruno Wolff III <bruno(at)wolff(dot)to> writes:

> On Thu, Mar 08, 2007 at 20:32:22 -0300,
> Jorge Godoy <jgodoy(at)gmail(dot)com> wrote:
>> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
>>
>> As I said, it is easy with a function. :-) I was just curious to see if we
>> had something like Oracle's NEXT_DAY function or something like what I
>> described (SET BOW=4; -- makes Thursday the first day of week):
>
> If you are actually using "date" you can get the effect you want by adding
> a constant integer to the date in the date_trunc function. That seems
> pretty easy.

I couldn't see where to specify that integer. Or, if it to sum it up to the
date, something that calculates it automatically.

http://www.postgresql.org/docs/8.2/interactive/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

Adding an integer I'd still have to write the verifications (such as the one I
mention below for Oracle's NEXT_DATE()) to get the desired result.

Just to repeat my question:

(I don't want to write a function, I can do that pretty easily... And I was
asking if there existed some feature on the database that... It's just a
curiosity)

Given a date X it would return me the first day of the week so that I can
make this first day an arbitrary day, e.g. Friday or Wednesday.

Oracle's NEXT_DAY() gets closer to that, but would still require a few
operations (checking if the returned date is before the given date or if after
then subtract one week from this returned value, kind of a
"PREVIOUS_DATE()"...).

With a function I could make it easily, but then I'd have to wrap all
calculations with that... It was just something to make life easier. From
the answers I'm getting I see that there's no way to do that without a
function and that I'm not missing any feature on PG with regards to that ;-)

--
Jorge Godoy <jgodoy(at)gmail(dot)com>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moran 2007-03-09 16:36:08 Re: HIPPA (was Re: Anyone know ...)
Previous Message Kevin Hunter 2007-03-09 16:29:28 Re: HIPPA (was Re: Anyone know ...)