Subtracting months from given date

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
adityavarma
Premium Member
Premium Member
Posts: 104
Joined: Thu Jul 12, 2007 11:32 pm
Location: Canada

Subtracting months from given date

Post by adityavarma »

Hi,

I have an requirment where i need to subtract months from the given date yyyymm,

can you please suggest me to achieve this without using any routine.


Regards,
Aditya
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

There is no specific functions available in PX for adding months. Whether you have to go for routinue or if your source is database you need to handle at source itself or if you have sequencer jobs you can handle using ICONV and OCONV or Basic Transformer(it is not Recommendable).
Cheers
Ravi K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why did you post in the server forum? Is there a maximum number of months? If so, a couple of stage variables, some If..Then..Else logic and some arithmetic should see you through.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
adityavarma
Premium Member
Premium Member
Posts: 104
Joined: Thu Jul 12, 2007 11:32 pm
Location: Canada

Post by adityavarma »

My Mistake, I have placed it in the server forum, it should be in parallel forum, dont know how to move it now.

There is no maximum number of months
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

adityavarma wrote:My Mistake, I have placed it in the server forum, it should be in parallel forum, dont know how to move it now.
You wait for the Moderator to stumble by. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

If the phrase "subtract months" is in a set pattern against the "yyyymm" format shown, then a fraction-of-12 calculation becomes easy to do.

The year is the integer portion, and your mm value is divided by 12 to convert it to decimal. Convert the number of months to be subtracted to decimal, do the subtraction (works just as well for addition) and change the decimal fraction back to its month equivalent.

You don't have worry about crossing the century year, since it is treated as an ordinary integer value.

You can, if you want to maintain precision without worrying about rounding, keep 12 stage variables with the decimal equivalent for each month. One month is 0.08333. Your table can be your "translation" of the month number to its decimal and back again.

Please note: You have to adjust for the fact that December divided by 12 is 1. That's why I described using a lookup "table" with stage variables.

In my days as an actuary, in the dinosaur age using Lotus 1-2-3 on dual-floppy IBM PCs, we had a standard and "coded" for it very easily.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
Post Reply