torturedmind
Programmer
Here is a small SQL showing that week 1 of the year starts with Jan. 1 and Sunday is day 1 of a week.
And here is the function version that accepts dates:
My question is, knowing that "IW" is the standard, are we the only ones (I mean, the company I work for) that requires such non-standard week numbering? My apologies but it confuses me how they designed the logic of IW and WW.
kilroy
philippines
"Once a king, always a king. But being a knight is more than enough."
Code:
SELECT
a.d dDate,
TO_CHAR(a.d, 'Dy') cDay,
TO_NUMBER(TO_CHAR(a.d, 'd')) nDay,
TO_NUMBER(TO_CHAR(a.d, 'ww')) nWeek,
TO_NUMBER(TO_CHAR(a.d, 'ww')) +
CASE WHEN TO_CHAR(a.d, 'ww') = TO_CHAR((a.d - TO_NUMBER(TO_CHAR(a.d, 'd'))), 'ww')
THEN 1
ELSE 0
END nCorrectWeek
FROM
(SELECT
TRUNC(SYSDATE, 'y') - 1 + ROWNUM d
FROM All_Objects
WHERE ROWNUM <= ADD_MONTHS(TRUNC(SYSDATE, 'y'), 12) - TRUNC(SYSDATE, 'y')) a;
And here is the function version that accepts dates:
Code:
create or replace function THWW
(
Date_Entry in date
) return number is
WWNum number;
begin
WWNum := TO_NUMBER(TO_CHAR(Date_Entry, 'ww')) +
CASE WHEN TO_CHAR(Date_Entry, 'ww') = TO_CHAR((Date_Entry - TO_NUMBER(TO_CHAR(Date_Entry, 'd'))), 'ww')
THEN 1
ELSE 0
END;
return WWNum;
end THWW;
My question is, knowing that "IW" is the standard, are we the only ones (I mean, the company I work for) that requires such non-standard week numbering? My apologies but it confuses me how they designed the logic of IW and WW.
kilroy
philippines
"Once a king, always a king. But being a knight is more than enough."