×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Week of the year

## Week of the year

(OP)
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
philippines

"Once a king, always a king. But being a knight is more than enough."

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!