number of week in year - oracle syntax

I've got some sql code which lists all the days within the last 4 weeks of the report run date.
I now need to add another field in which calculates the week number (in the year). The to_char(d, 'ww') function doesnt quite fit my requirements - i need a week to run from Mon-Sun, not Sat-Fri.
Fig1. is the current output (using the code below), Fig2. is the desired output.
Any help with the code is appreciated output.xls
SELECT d asm_date, TO_CHAR(d, 'Day') day_of_week, to_char(d, 'ww') week_no
  FROM (SELECT NEXT_DAY(TRUNC(SYSDATE - 1), 'Sunday') - LEVEL + 1 d
          FROM DUAL
        CONNECT BY LEVEL <= 28)
ORDER BY 1

Open in new window

tonMachine100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JacobfwCommented:
Like this (just added 2 days for the week calculation):

SELECT d asm_date, TO_CHAR(d, 'Day') day_of_week, to_char(d-2, 'ww') week_no
  FROM (SELECT NEXT_DAY(TRUNC(SYSDATE - 1), 'Sunday') - LEVEL + 1 d
          FROM DUAL
        CONNECT BY LEVEL <= 28)
ORDER BY 1
0
JacobfwCommented:
Gets a little funky around the yearend though.  What do you want for the last week/first week of the year?
0
sdstuberCommented:
are you counting whole weeks or partial weeks too?

for instance 2011 starts on a Saturday.  Is week 1 of 2011 a 2-day week?  Or, do you start counting weeks from the first full week of the year?

Are you looking for iso weeks?   if so, try iw format


SELECT d asm_date, TO_CHAR(d, 'Day') day_of_week, to_char(d, 'iw') week_no
  FROM (SELECT NEXT_DAY(TRUNC(SYSDATE - 1), 'Sunday') - LEVEL + 1 d
          FROM DUAL
        CONNECT BY LEVEL <= 28)
ORDER BY 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.