Week Number problem

I have the following function to produce the week number from a given date:

<CFFUNCTION NAME="GetWeekNo" RETURNTYPE="String">
  <CFARGUMENT NAME="MDate" DATATYPE="Date" REQUIRED="True">
  <CFIF Year(MDate) EQ 2012 OR Year(MDate) EQ 2017 OR Year(MDate) EQ 2023 OR
  Year(MDate) EQ 2034 OR Year(MDate) EQ 2040 OR Year(MDate) EQ 2045 OR
  Year(MDate) EQ 2051 OR Year(MDate) EQ 2062>
    <CFRETURN LZero(DatePart("ww",MDate))>
  <CFELSE>
    <CFRETURN LZero(DatePart("ww",MDate)-1)>
  </CFIF>
</CFFUNCTION>

The function works properly (the years mentioned in the function are to re-align the weeks because 01/01/year in those years produces week 00)

My boss now wants the week numbers to correspond with those in MSOutlook, with the first week of the year being the first full week.

I have tried manipulating the code in the function but I am getting in a mess!  Can someone please help me work it out?
LVL 3
jdthedjAsked:
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.

Kevin CrossChief Technology OfficerCommented:
What happens when you just simply return:
LZero(DatePart("ww",MDate))

The 01/01/YYYY combinations that return week 00 are probably because they are at the end of the 53rd week in the previous year ... therefore, I suspect that you don't need to adjust the response. Guess you could test if it is zero before return and if so change to literal 53 or test LZero(DatePart("ww", DateAdd("d", -5, MDate))) ...
0
jdthedjAuthor Commented:
Thanks for the reply mwvisa1.  

I have tried every which way but there are always exceptions.  When I just use LZero(DatePart("ww",MDate)) 01/01/2013 returns week one instead of week 53.  01/01/2012 returns week one instead of week 52.  01/01/2011 does the same.  

I need a formula of some sort which knows when the full week is present at the start of a year, and then makes all the rest of the year follow logically on.
0
Kevin CrossChief Technology OfficerCommented:
Sorry for the delay ... was thinking of what would be your best approach given you have to not only find the adjusted week number for 1/1 when it doesn't start off the week but also maintain whatever adjustment is made through out calls for additional week numbers which would almost make you have to check for 1/1 on every single call to see if it is adjusted and then adjust your normal week number by that same amount. Actually that is probably it as you can take the year of the passed date and then determine the week number of 1/1 along with its day of the week. If it is week 1 and on day after what you consider the week start (i.e., Sunday or Monday) then you will know to -1 all responses. If it is 0 or 53, you can also determine what you want done.
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
jdthedjAuthor Commented:
I have gone for a very roundabout method - not the best approach.  Basically I take the date of the first Monday in the year, then loop to add a week until it reaches the target date.  At least it only has to loop 52 times at most.  The problem comes at year end/start when the week number returned = 0.  In this case I return the week number for 31st December.  The main thing is it works!

Thanks agian for you input.
0
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
ColdFusion Language

From novice to tech pro — start learning today.