Subject RE: [firebird-support] Extract "name of the day" from date
Author Helen Borrie
At 01:58 AM 6/02/2009, Svein Erling Tysvær wrote:
>Alternatively (if you don't like UDFs), you can use something like (using 31 December 1899 since that apparently was a Sunday, use 1 January 1900 if you think the week starts on Monday, note that that date must be prior to any date you want to know the day of):
>
>Select case current_date - cast('31.12.1899' as Date) -
> ((current_date - cast('31.12.1899' as Date))/7)*7
> when 0 then 'Sunday'
> when 1 then 'Monday'

....

Less trouble to use the EXTRACT(WEEKDAY FROM ADATE), viz.

select
....
case extract (weekday from adate)
when 3 then 'Wednesday'
when 0 then 'Sunday'
...
when 6 then 'Saturday'
end
as D_o_W,
...

Another approach is to return the short integers to the client and have an enumeration/localization declared client-side to deal with the conversion to weekday names; otherwise, you are stuck with English (or whatever language you used).

(Note, I put Wednesday first here because I suspect that Fb 1.5 sets the varchar length from the first case. V.2 addressed these length overflow issues for unions and *I think* also did so for CASE structures.)

./hb