- --------------------------------------------------------------------------------------------------------------
- -- Retrieve first date of week
- --------------------------------------------------------------------------------------------------------------
-
- FUNCTION getFirstDateOfWeek(vi_week_number IN INTEGER,
- vi_year IN INTEGER)
- RETURN DATE
- IS
- v_first_monday_of_the_year INTEGER;
- v_value INTEGER;
-
- BEGIN
-
- v_first_monday_of_the_year := -1;
- v_value := 0;
-
- WHILE v_value <> 2 /*Find first Monday*/
- LOOP
- v_first_monday_of_the_year := v_first_monday_of_the_year + 1;
- v_value := TO_CHAR(TO_DATE(vi_year || '0101', 'YYYYMMDD') + v_first_monday_of_the_year, 'D');
- END LOOP;
-
- RETURN TO_DATE(vi_year || '0101', 'YYYYMMDD')+(v_first_monday_of_the_year + (7 * (vi_week_number - 2)));
-
- END;
--------------------------------------------------------------------------------------------------------------
-- Retrieve first date of week
--------------------------------------------------------------------------------------------------------------
FUNCTION getFirstDateOfWeek(vi_week_number IN INTEGER,
vi_year IN INTEGER)
RETURN DATE
IS
v_first_monday_of_the_year INTEGER;
v_value INTEGER;
BEGIN
v_first_monday_of_the_year := -1;
v_value := 0;
WHILE v_value <> 2 /*Find first Monday*/
LOOP
v_first_monday_of_the_year := v_first_monday_of_the_year + 1;
v_value := TO_CHAR(TO_DATE(vi_year || '0101', 'YYYYMMDD') + v_first_monday_of_the_year, 'D');
END LOOP;
RETURN TO_DATE(vi_year || '0101', 'YYYYMMDD')+(v_first_monday_of_the_year + (7 * (vi_week_number - 2)));
END;