END-OF_MONTH, ADD_MONTHS, NUM_OF_WEEKS

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
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

END-OF_MONTH, ADD_MONTHS, NUM_OF_WEEKS

Post by gateleys »

given a date (say, 09/14/2005),
1. how to compute end of the month?
2. how to add/subtract 9 months from the above end of month?

Suppose, another date (say, 01/19/2005) is also given, how to compute the number of weeks between the two dates?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard! :D

Start by reviewing Transforms such as MONTH.LAST, MONTH.FIRST and so on.

Then search the forum for suggestions.

Get back if you're still struggling.

Adding weeks is easy. It's adding (7 * days). Since dates are stored internally as days (search for Iconv() function), this is simple arithmetic in DataStage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

ray.wurlod wrote:Welcome aboard! :D

Start by reviewing Transforms such as MONTH.LAST, MONTH.FIRST and so on.

Then search the forum for suggestions.

Get back if you're still struggling.

Adding weeks is easy. It's adding (7 * days). Since dates are stored internally as days (search for Iconv() function), this is simple arithmetic in DataStage.
HI,
how about adding months including leap year constraints :roll:

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

Post by ray.wurlod »

I have a bulletproof routine for doing that. Anyone who engages my professional services for DataStage is entitled to the suite, which includes AddDays, AddWeeks, AddMonths and AddYears (both to dates and to timestamps), fully documented and tested.

Essentially the algorithm is to add the months, adjusting year if necessary, then rewind the day number until a legal date is encountered. Plus some variation when the offset number is negative. Plus a whole lot of idiot-proofing to take account of invalid input arguments.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

Thanks Ray, I got the work done.

[quote="kumar_s"][quote="ray.wurlod"]Welcome aboard! :D

Start by reviewing Transforms such as MONTH.LAST, MONTH.FIRST and so on.

Then search the forum for suggestions.

Get back if you're still struggling.
Post Reply