date difference

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
developeretl
Participant
Posts: 89
Joined: Sat Jul 24, 2010 11:33 pm

date difference

Post by developeretl »

Iam having the date difference issue
I have a col1 with some codes like A,B,C and another col with dates ,date column in this format 20100724
So my condition is that if Col1 is 'A' then populate a column with the one year reduced that is difference 1. Can you please help me with this issue

Example: if col1='A' then ( 20100724) in the result i should get 20090724
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Re: date difference

Post by kris007 »

You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.
Kris

Where's the "Any" key?-Homer Simpson
developeretl
Participant
Posts: 89
Joined: Sat Jul 24, 2010 11:33 pm

Re: date difference

Post by developeretl »

kris007 wrote:You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.
Hi Kris,
Iam doing the difference for year only.
developeretl
Participant
Posts: 89
Joined: Sat Jul 24, 2010 11:33 pm

Re: date difference

Post by developeretl »

kris007 wrote:You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.
Hi Kris,
Iam doing the difference for year only.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Re: date difference

Post by kris007 »

Yes. But what if your input date is 20080229. What should be your output? 20070229 (which is invalid) or 20080228.
Kris

Where's the "Any" key?-Homer Simpson
datisaq
Participant
Posts: 154
Joined: Wed May 14, 2008 4:34 am

Post by datisaq »

But i think it needs date to string conversions before doing that...
Or Is it implicit??
IBM Certified - Information Server 8.1
Post Reply