Subject | Re: [firebird-support] EXTRACT(WEEK FROM DATE) ?? |
---|---|
Author | Florian Hector |
Post date | 2005-06-21T11:40:18Z |
> Does anyone knows if FB2 will have support for WEEK number in theIMHO, this would not make much sense, since week number is not the same
> EXTRACT() function?
>
> I find many DATE related capabilities in FB and in many UDF's, but can't
> find support for WEEK number.
> Only to WeekDay.
all over the world. For example, here in Germany you can have the case
that the the date 02.01. in a year can be the 53rd week of the previous
year. The rule of thumb for Germany is: The week with the first Thursday
in a year defines the first week of the year.
Use this stored procedure and adapt it to your specific needs:
CREATE PROCEDURE WEEKOFYEAR (
DATTIM TIMESTAMP)
RETURNS (
WEEKNR SMALLINT,
OFYEAR SMALLINT)
AS
begin
if (dattim is null) then
begin
weeknr = null;
ofyear = null;
end
else
begin
/*
week number and corresponding year relate to
thursday of the concerning week (Mon ... Sun)
*/
dattim = dattim - extract( weekday from (dattim - 1)) + 3
/* orig: Sun = 0 ... Sat = 6
to: Mon = 0 ... Sun = 6 */
/* => Mon of week */
/* => Thu of week */;
weeknr = (extract( yearday from dattim) / 7) + 1;
ofyear = extract( year from dattim);
end
suspend;
end
Florian