How to compute the week of the month

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
rob1
Participant
Posts: 5
Joined: Wed Sep 03, 2003 8:49 am

How to compute the week of the month

Post by rob1 »

How could I compute the week of the month for a date.
The week #1 begins on the first day of the month and end on the first sunday .
If somebody has a routine, let me know it
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Search the forum. There are quite a few routines similar to your requirement.

Try using IConv.

(YourDate - FirstDateOfTheYear) / 7

You can deduce the first day of the week and adjust current week no.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
Another possible work around,
Assingh some variables for value for each day say sunday = 7 monday = 6, tuesday = 5....

Let the date to find be 16-09-2005

find the the first day of the month(01-09-2005) Thursday

subract the respective variable from the date,
i.e., 16 - 4 (Thrusday) = 12
find ceil(12/ 7)+1 = 3

IHTH
regards
kumar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Mod(DayNumber, 7) returns 0 for Sunday and 6 for Saturday where DayNumber is in DataStage internal format.

Applying that knowledge to the date you're testing and to the first day of the same month (see also MONTH.FIRST Transform) should give you an elegant solution.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply