Page 1 of 1

END-OF_MONTH, ADD_MONTHS, NUM_OF_WEEKS

Posted: Wed Sep 28, 2005 11:03 pm
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?

Posted: Wed Sep 28, 2005 11:07 pm
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.

Posted: Thu Sep 29, 2005 1:23 am
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

Posted: Thu Sep 29, 2005 1:26 am
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.

Posted: Thu Sep 29, 2005 9:54 pm
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.