date manipulation

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

date manipulation

Post by gsym »

Hi All,
I have a problem while manipulating the date. My source and target are DB2 databases.
Job Design is
DB2 API --> TRANSFORMER -->DB2 API
-->DB2 API (reject link)

Here is the logic iam using to find whether the age is greater than 16 yrs and less than 85 yrs.

Created a stage variable DOB with this condition :
If(Iconv(DSJobStartDate,"D-YMD[4,2,2]") -
Iconv(ToTransformer.BIRTHDATE,"D/MDY") > 5840 AND Iconv(DSJobStartDate,"D-YMD[4,2,2]") - Iconv(ToTransformer.BIRTHDATE,"D/MDY") < 31025) then 1 else 0

Constraint DOB = 0 THEN TO THE REJECT TABLE.

If the age is less than 16 yrs and greater than 85 then that record should be rejected.

The records with DOB as " 01/03/1968" , 01/12/1968, 01/06/1968 are getting rejected though they are valid (greater than 16 yrs and less than 85 yrs).

Any help is appreciated.

Thanks
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Re: date manipulation

Post by kris »

gsym wrote:Hi All,
Created a stage variable DOB with this condition :
If(Iconv(DSJobStartDate,"D-YMD[4,2,2]") -
Iconv(ToTransformer.BIRTHDATE,"D/MDY") > 5840 AND Iconv(DSJobStartDate,"D-YMD[4,2,2]") - Iconv(ToTransformer.BIRTHDATE,"D/MDY") < 31025) then 1 else 0

Constraint DOB = 0 THEN TO THE REJECT TABLE.

If the age is less than 16 yrs and greater than 85 then that record should be rejected.

The records with DOB as " 01/03/1968" , 01/12/1968, 01/06/1968 are getting rejected though they are valid (greater than 16 yrs and less than 85 yrs).


You may not want to use DSJobStartDate macro in this case.
Instead, you can use system variable @Date which is in internal format.

Try this:
If @date - Iconv(BIRTHDATE,"D/MDY") > 5840 and @date - Iconv(BIRTHDATE,"D/MDY") < 31025 then Ans=1 else Ans=0
~Kris
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Re: date manipulation

Post by gsym »

kris,

I tried with system variable @Date , still the same problem........
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Re: date manipulation

Post by kris »

Did you this:
If @date - Iconv(ToTransformer.BIRTHDATE,"D/MDY") > 5840 and @date - Iconv(ToTransformer.BIRTHDATE,"D/MDY") < 31025 then Ans=1 else Ans=0
~Kris
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Re: date manipulation

Post by gsym »

yes, the logic is
If(@DATE -
Iconv(ToTransformer.BIRTHDATE,"D/MDY") > 5840 AND @DATE - Iconv(ToTransformer.BIRTHDATE,"D/MDY") < 31025) then 1 else 0[/quote]
srimitta
Premium Member
Premium Member
Posts: 187
Joined: Sun Apr 04, 2004 7:50 pm

Post by srimitta »

What is this "5840" and "31025" ? No.of Days?
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Post by kris »

Yes it is number of days for both 16 years and 85 years @365 days.

Gsym,

Because this logic doesn't consider all the leap years into account, it may not be giving you the accurate Age but is close though.
~Kris
gsym
Charter Member
Charter Member
Posts: 118
Joined: Thu Feb 02, 2006 3:05 pm

Post by gsym »

Kris,

At present iam looking for a close value for the No of days.

But, the problem is with the rejected records.

why The records with DOB as 01/03/1968, 01/12/1968, 01/06/1968 are getting rejected though they are valid (greater than 16 yrs and less than 85 yrs)?
Last edited by gsym on Mon Aug 27, 2007 2:48 pm, edited 1 time in total.
satya99
Participant
Posts: 104
Joined: Thu Nov 30, 2006 1:22 pm

date manipulation

Post by satya99 »

Try this logic:

Create three stage variable

sv1 Iconv("01/03/1968", "D2/")
sv2 (@DATE - sv1)/365
sv3 IF sv2 > 16 AND sv2 < 85 Then @True else @False

Good luck
satya
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

gsym,
I think Satya99 might have the right approach - that your ICONV() isn't converting the date as expected; in which case it will return the original string and which, in turn, is causing your condition to return an unexpected result. Ensure that the ICONV() of your value is successful. I would test it with a dummy output column to a test file for checking, or to use the debugger.
kris
Participant
Posts: 160
Joined: Tue Dec 09, 2003 2:45 pm
Location: virginia, usa

Post by kris »

I have tried it on my system and it seems to be working fine for those dates too.

"D/MDY" seems to be handling both single digit and double digit months on my system.

But Like ArndW said, Satya99's approach of using "D2/" or "D2/MDY" would be more appropriate thing to do.

But always I would prefer to validate dates (using a simple validation routine) if they are valid before applying any calculations or transformations on them.
~Kris
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Wouldn't the job be easier to maintain if you calculated the actual ages (in stage variables, perhaps) and compared those?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
srimitta
Premium Member
Premium Member
Posts: 187
Joined: Sun Apr 04, 2004 7:50 pm

Post by srimitta »

Post Reply