|Subject||Re: [firebird-support] Extract weekday|
> > > >Acording to Helen's book extract weekdays returns values 0..6 (0 isI got this one from Ivans page ... seems to work fine:
> > > >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
> > returns extract(weekday from aDate - 1) + 1;
> >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).
select extract(weekday from (current_date - 2) - 1) + 1
"current_date - 2" = Sunday for today :-)
The select returns "7"
> A CASE expression will do it, though:Of course, this works as well and is even more clear :-)
> case when (extract (weekday from aDate) = 0) then 7
> else (extract (weekday from aDate) end;
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL