Page 1 of 1

Subtracting months from given date

Posted: Sun Jan 23, 2011 10:41 pm
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

Posted: Sun Jan 23, 2011 10:58 pm
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).

Posted: Sun Jan 23, 2011 11:39 pm
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.

Posted: Sun Jan 23, 2011 11:46 pm
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

Posted: Mon Jan 24, 2011 7:34 am
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:

Posted: Mon Jan 24, 2011 12:11 pm
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.