Subtracting 2 dates in Transformer

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

pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Subtracting 2 dates in Transformer

Post by pkl »

Hi,

I know that there have been some posts relating to date conversions. I've read every one of them but I cudn't acheive what I wanted.

I have 2 dates from different tables . In the Xfm I need to subtract one from the other.

I'm trying to do something like this.


Var1=Iconv("DSLink1.FieldName[1,10]","DYMD")
Var2=Iconv("DSLink2.FieldName[1,10]","DYMD")
Result=Var1-Var2

My Result returns '0'

Can anybody pls help me.


Thanks
Preethi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What exactly do your date fields look like?
-craig

"You can never have too many knives" -- Logan Nine Fingers
pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Post by pkl »

Hi Craig,

My date field is in the Timestamp format :YYYY-MM-DD HH24:MI:SS

Thanx
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok, that seems fine. It looks like you are using Stage Variables rather than a custom routine, is that correct? Can you cut and paste the actual derivations you are using, please and use the 'code' tags so they format nicely? It always worrys me when someone says "I'm trying to do something like this". :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Post by pkl »

Hi Craig,

You are correct, I am using the Stage variables .

My code is:

StageVar1=Iconv(DSLink1.DATE[1,10],'DYMD')
StageVar2=Iconv(DSLink2.DATE2[1,10],'DYMD')
Result = StageVar1 - StageVar2

And I assign the "Result" as derivation for a column in the target.


Hope I am clear this time. Excuse me if I am not again.

I appreciate your help.

Thanks
Preethi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not sure what to tell you as this should work fine - as long as you have data. I threw this into a scratch routine and it subtracted the two timestamps just fine. The only time I got a zero was if both were the same or if both were blank.

Any chance of that? Have you run your job through the Debugger to check what actual values are coming in with those fields?
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Why not create a temporary output file containing the results of each of your stage variables and run it for a couple of rows?

The ICONV statement returns an integer number that equates to the number of days passed since Jan 1, 1968. So, for May 17, 1995 the number is 10000. If ICONV cannot "internalize" your date, then it returns a blank. So, if your ICONV is not handling your date format (try just "D") then it may be returning blank. So, blank - blank = blank.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Post by pkl »

Hi Ken & Craig,


I tried to debug.... My Stage Variables have '0' in them ICONV is not able to internalise the data.

I'm not sure whether I am specifying the right format string for the Iconv function.

I'm sure the data is not null or 0.

Are there any other ways to do this.

Thanks a lot .

Preethi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Post an example (or two) of what your data actually looks like. It must not be in Timestamp format after all.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Post by pkl »

Hi,

These are 2 sets of dates that I need to subtract
Date1=2003-08-30 00:00:00
Date2=2003-08-30 00:00:00

Date1=2003-06-30 00:00:00
Date2=2003-06-16 00:00:00

If I try to do it in the OCI it works fine if I subtract the values directly.

But I can do that only if the values are from the same table.

But now I need to subtract dates from different tables.
Then I have to do it in the Xfm.

I dont know how else I can do this.


Appreciate your help very much.

Regards
Preethi
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

This is getting frustrating. I'm guessing you just pasted the format returned from the OCI/ODBC stage you're using, not what truly exists in the transformer at the time the math is happening. I asked you to write out the values from the transformer stage variables into a file and look at them there.

Dollars to donuts, you're selecting from either DB2 or Informix which returns dates in the INTERNAL format already. Therefore, the extra ICONV is blanking out your "date" because it's no longer a date.

Do I win the donuts?
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
pkl
Participant
Posts: 50
Joined: Wed Aug 11, 2004 11:45 am

Post by pkl »

Hi Ken & Craig,

Thankyou very much for being so pateint with me and I'm extremely sorry for frustrating you.

It is working now.

I greatly appreciate your help.

Thanks Once again


Regards
Preethi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So, what made it work for you? Best to post the actual solution so that others can learn from it. That and so we can settle Ken's donut dillema. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

What was the problem? I'm not frustrated with you, just the problem. We need to know what you were doing wrong so that everyone following this post learns from your experiences. Plus, they will see the train of thought we try to take people thru in order to troubleshoot issues.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

mmmm donut


My kingdom for a donut.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply