Number of the week - Oconv code

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Number of the week - Oconv code

Post 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 ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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).
Last edited by ray.wurlod on Fri Feb 09, 2007 4:06 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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)
Last edited by DSguru2B on Fri Feb 09, 2007 4:07 pm, edited 1 time in total.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Too simplistic, grasshopper. See above.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Post 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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Post by gsym »

As far as I can ascertain, the first day of the first week starts on Jan 1st of the year.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Post 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 ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Post 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
Post Reply