Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

Week Number problem

Posted on 2010-08-18
Medium Priority
394 Views
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?
0
Question by:jdthedj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 60

Expert Comment

ID: 33471225
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

LVL 3

Author Comment

ID: 33471388

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

LVL 60

Accepted Solution

Kevin Cross earned 2000 total points
ID: 33478060
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

LVL 3

Author Comment

ID: 33480808
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

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month10 days, 7 hours left to enroll