Re: Setting week starting day - Mailing list pgsql-general

From Jorge Godoy
Subject Re: Setting week starting day
Date
Msg-id 87d53j9urd.fsf@gmail.com
Whole thread Raw
In response to Re: Setting week starting day (was: Re: Tabulate data incrementally)  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: Setting week starting day
List pgsql-general
Alvaro Herrera <alvherre@commandprompt.com> writes:

> Jorge Godoy escribió:
>
>> I mean, if I wanted to do the above but instead of Sunday or Monday as the
>> starting day I'd like using Fridays or Wednesdays...
>>
>> Is it possible?  Writing a new function shouldn't be too hard -- it's a matter
>> of truncating the week on a day and shifting the date forward or backward --,
>> but something like a "SET bow=5" (to make the API consistent with the 'dow'
>> that already exists) would be really great!
>
> Is it not just a matter of adding a constant and then taking modulo 7?

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):

================================================================================
NEXT_DAY

Syntax


Purpose
Returns the date of the first weekday named by char that is later than the
date d. The argument char must be a day of the week in the date language of
your session, either the full name or the abbreviation. The minimum number of
letters required is the number of letters in the abbreviated version. Any
characters immediately following the valid abbreviation are ignored. The
return value has the same hours, minutes, and seconds component as the
argument d.


Example

This example returns the date of the next Tuesday after March 15, 1998.

SELECT NEXT_DAY('15-MAR-98','TUESDAY') "NEXT DAY"
     FROM DUAL;

NEXT DAY
---------

16-MAR-98
================================================================================


So, I'd have something like: "SELECT NEXT_DAY(now()+'5 weeks'::INTERVAL,
'THURSDAY');" to give me the next Thursday 5 weeks from now.


Be seeing you,
--
Jorge Godoy      <jgodoy@gmail.com>

pgsql-general by date:

Previous
From: "David Legault"
Date:
Subject: Re: security permissions for functions
Next
From: "jws"
Date:
Subject: Can psql show me where my script is broken?