Page 1 of 1

Number of the week - Oconv code

Posted: Fri Feb 09, 2007 3:50 pm
by gsym
Hi there folks,

Can anyone tell me what the conversion code is to get the number of the week in a year corresponding to a supplied internal date using OCONV ?

Posted: Fri Feb 09, 2007 4:05 pm
by ray.wurlod
There isn't one.

The reason is that the week number is determined by a business rule. On what day does a week start? How is week number 1 in a year defined (all weeks must have seven days, so "starts on Jan 1" is not a good rule).

Look at the Transform WEEK.TAG and the WeekTag routine that it calls. These document one business rule (from memory, week begins on a Monday, and week 1 is the first week that contains four calendar dates in that year).

Posted: Fri Feb 09, 2007 4:06 pm
by DSguru2B
No such conversion code but not hard to do it.
If going by calender weeks, you can do something like

Code: Select all

INT(OCONV(InternalDate, "DJ")/7)

Posted: Fri Feb 09, 2007 4:06 pm
by ray.wurlod
Too simplistic, grasshopper. See above.

Posted: Fri Feb 09, 2007 4:08 pm
by DSguru2B
Yea. I read your post after hitting the reply button on my end. But if the OP needs the week of the year going by calender date and not a business date, my way should work :roll: . For other dates, more information is needed.

Posted: Fri Feb 09, 2007 4:17 pm
by gsym
oh, ok......guess I gotta find out the business rule required here then. Or just do it like DSguru suggested.

Thanks for the answers.

Posted: Fri Feb 09, 2007 4:19 pm
by DSguru2B
No. Dont just do it like I suggested. If there is a business requirement to it then get that and then tackle it. If its just calender days then you can do it as I suggested.

Posted: Fri Feb 09, 2007 4:19 pm
by gsym
As far as I can ascertain, the first day of the first week starts on Jan 1st of the year.

Posted: Fri Feb 09, 2007 4:20 pm
by DSguru2B
gsym wrote:As far as I can ascertain, the first day of the first week starts on Jan 1st of the year.
Confirm that from your BA. If thats the case, then you can use my code.

Posted: Sat Feb 10, 2007 4:54 am
by ray.wurlod
Alert your BA to the fact that that decision will mean that week #53 in the year has fewer than seven days, and that roll-ups by week will be invalid.

Posted: Mon Feb 12, 2007 4:35 pm
by gsym
ray.wurlod wrote:Alert your BA to the fact that that decision will mean that week #53 in the year has fewer than seven days, and that roll-ups by week will be invalid.
Yes, rollups will be a problem, never though of that. What is a possible solution for this dilemma ?

Posted: Mon Feb 12, 2007 5:41 pm
by ray.wurlod
On what day does a week start? How is week number 1 in a year defined (all weeks must have seven days, so "starts on Jan 1" is not a good rule).

Solution #1
Look at the Transform WEEK.TAG and the WeekTag routine that it calls. These document one business rule (from memory, week begins on a Monday, and week 1 is the first week that contains four calendar dates in that year).

Solution #2
Find a BA who thinks things through rather than taking the path of least resistance.

Posted: Tue Feb 13, 2007 2:33 pm
by gsym
ray.wurlod wrote:On what day does a week start? How is week number 1 in a year defined (all weeks must have seven days, so "starts on Jan 1" is not a good rule).

Solution #1
Look at the Transform WEEK.TAG and the WeekTag routine that it calls. These document one business rule (from memory, week begins on a Monday, and week 1 is the first week that contains four calendar dates in that year).

Solution #2
Find a BA who thinks things through rather than taking the path of least resistance.
Thanks Ray, solution 2 is out, doesn't look like anybody cares (but me) .......looking at solution 1