Subject | Re: [firebird-support] Extract weekday |
---|---|
Author | Martijn Tonies |
Post date | 2005-04-19T15:24:41Z |
> > > >Acording to Helen's book extract weekdays returns values 0..6 (0 isI got this one from Ivans page ... seems to work fine:
> >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).
select extract(weekday from (current_date - 2) - 1) + 1
from rdb$database
"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 :-)
>
> select
> case when (extract (weekday from aDate) = 0) then 7
> else (extract (weekday from aDate) end;
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server
Upscene Productions
http://www.upscene.com