how to subtract the month from yyyymmdd

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
deesh
Participant
Posts: 193
Joined: Mon Oct 08, 2007 2:57 am

how to subtract the month from yyyymmdd

Post by deesh »

Hi friends,

Can any one help me how to susbtract month from YYYYMMDD. Please look a exaple below.

next order date CCNPOD = 20100225
interval CCMPMO = 6
result should be : 20090825

CCMPMO ---Decimal (2)
CCNPOD ---Decimal( 8 )
Last edited by deesh on Fri Jun 19, 2009 5:31 am, edited 2 times in total.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The DateFromDaysSince function is what you are looking, described on page 593 of the Parallel Job Developer Guide
deesh
Participant
Posts: 193
Joined: Mon Oct 08, 2007 2:57 am

Post by deesh »

ArndW wrote:The DateFromDaysSince function is what you are looking, described on page 593 of the Parallel Job Developer Guide ...
Thanks for your reply, This DateFromDaysSince is not correct for my logic, actually I want If my date is 20100225 from that I have to minus the 6 moths so the result is 20090825, Please look my example once.
vkhandel
Participant
Posts: 35
Joined: Wed Oct 04, 2006 12:12 am
Location: Pune

Post by vkhandel »

the desired output could be achieved by following logic implemented in transformer stage stage variables written in following order -

SVarDate (varchar8 ) --> decimaltostring(CCNPOD,"suppress_zero")
SVarCounter (varchar 2) --> decimaltostring(CCMPMO,"suppress_zero")
SVarMonth (varchar 2)--> If SVarDate[5,2] - SVarCounter < 0 then SVarDate[5,2] + 12 - SVarCounter else SVarDate[5,2] - SVarCounter
SVarYear (varchar 4)--> If SVarDate[5,2] - SVarCounter < 0 then SVarDate[1,4] - 1 else SVarDate[1,4]

and on the output link derivation , just concatenate the above variables as
Result --> SVarYear:SVarMonth:SVarDate[7,2]
Sreenivasulu
Premium Member
Premium Member
Posts: 892
Joined: Thu Oct 16, 2003 5:18 am

Post by Sreenivasulu »

I do not think there is any such built-in function or routine in datastage.
You need to build a custom routine to get the solution. The custom routine would need to access database and get the result.

Regards
Sreeni
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You need to specify your definition of what a month is. What about 2010-01-31? Since June doesn't have 31 days what do you do? Once your rules about months are set, you can use the DateFromDaysSince function. Otherwsise you could convert your date into 3 components, do your math on them, then put them back togethr to a date along the lines of what vkhandel has posted.
Post Reply