Subject Re: [ib-support] udf crashes firebird
Author Ivan Prenosil
From: "Nick Upson" <uebridger@...>
> > > using FB1.0.2 but I can't get EXTRACT(WEEKDAY FROM 'today'- 1) + 1 to
> >work
> >
> >That's because 'today' is string - you can't subtract numbers from string.
> >Either cast it to date (or timestamp, so it can work with dialect-1 too):
> >
> > EXTRACT(WEEKDAY FROM CAST('today' AS TIMESTAMP) - 1) + 1
> >
> >or better yet use CURRENT_DATE or CURRENT_TIMESTAMP instead:
> >
> > EXTRACT(WEEKDAY FROM CURRENT_TIMESTAMP - 1) + 1
>
> I thought today was a reserved word for a date, learn something new

'today' is in apostrophes, hence it is not reserved word, but string literal of type char(5).

>
> why the -1 and +1 on the end? without them I get a result of 2 for today,
> which is correct.

Right, but without -1 and +1 you will get 0 (zero) for Sunday.
The comment in your UDF said:
"fn_dowi() return the day of today as integer, Monday = 1, Sun = 7, etc"
so I thought you would prefer 7 for Sunday.


Ivan Prenosil
[ I am looking for a job: InterBase - Firebird - Delphi - C - fulltext db - and more ... ]
Ivan.Prenosil@...
http://www.volny.cz/iprenosil/interbase