Subject Re: [firebird-support] Extract weekday
Author Helen Borrie
At 04:17 PM 19/04/2005 +0200, you wrote:


> > >Acording to Helen's book extract weekdays returns values 0..6 (0 is
>Sunday).
> > >Could it be somewhere configured, that we get 1..7 (1 is Monday) ?
> > >Or maybe aditional approach ?
> >
> > EXTRACT (WEEKDAY FROM myDate) +1
>
>Which means 1 = Sunday, not 1 = Monday.
>
>:-)

Erp, yes. Subtract 1.


>Now, wouldn't Stored Functions be nice... :-/
>
>function ExtractWeekday(aDate: DATE): SmallInt
>as
>begin
> returns extract(weekday from aDate - 1) + 1;
>end;
>
>Pitty this isn't making it into Fb 2... :-/

Since it only has to roll Sunday over from 0 to 7, this won't give the
right result either. (Monday is already 1).

A CASE expression will do it, though:

select
case when (extract (weekday from aDate) = 0) then 7
else (extract (weekday from aDate) end;

./hb