Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Week of the year

Status
Not open for further replies.

torturedmind

Programmer
Jan 31, 2002
1,052
PH
Here is a small SQL showing that week 1 of the year starts with Jan. 1 and Sunday is day 1 of a week.
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 [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top