Improve a difference between two dates

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
Alethesnake
Participant
Posts: 56
Joined: Mon Mar 26, 2007 8:48 am
Location: Blue Bay (La Spezia)

Improve a difference between two dates

Post by Alethesnake »

Hi to everyone,
I've a problem with a difference between two dates.
I have improved a lookup between an oledb stage (sserver 2005) and an hashed file previously filled in another job with data get from a sql server table.
In the transformer where I perform the lookup, I need to obtain a difference (in days) between two dates (the former is from the oledb stage and the latter from the hashed file).
The two dates have the same format, that is datetime in sql server and become timestamp in datastage. (i.e. 2007-01-15 00.00.0..)
I'm trying to use the function DateGenericDateDiff(%date1%,%date2%) but I don't obtain valuable results (only impossible date/time conversion warnings)

Could you suggest me where is the problem? Thanks a lot for any help.

I tried unsucccessfully:

DateGenericDateDiff(lnk1.startDate,lnk2.endDate)
DateGenericDateDiff(lnk1.startDate[1,10],lnk2.endDate[1,10])

And as test:
DateGenericDateDiff("20070101", "20070401")
DateGenericDateDiff(Oconv(Iconv("01012007","D MDY[2,2,4]"),"D-YMD[4,2,2]"), Oconv(Iconv("04012007","D MDY[2,2,4]"),"D-YMD[4,2,2]"))
...
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

why do you make things so complicate.

With an iconv you get any date into an integer (0= 31.12.1967) and if you calculate the one integer minus the other you get the difference in days.
Wolfgang Hürter
Amsterdam
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

In other words, just use IConv to convert both date portions to 'internal' (integer) format and subtract them - the answer will be the difference in days.

If you really want to use the 'DateGenericDateDiff' transform, it uses the 'DateGenericToTimestamp' transform to transform the date and handles quite a number of different formats as noted in its' description. Your examples should have worked fine. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Alethesnake
Participant
Posts: 56
Joined: Mon Mar 26, 2007 8:48 am
Location: Blue Bay (La Spezia)

Post by Alethesnake »

Thanks a lot for your answers, I think I'll use Iconv :)
Only a question: are there some differences by improving the date-difference in a routine and use a transform function instead of directly in the transformer stage ? (firstly loss of performance)?

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

Post by kcbland »

Check this out:

viewtopic.php?t=85788

Don't worry about minor performance differences. You're going to do this type of date math a lot so use an encapsulated function.
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
Alethesnake
Participant
Posts: 56
Joined: Mon Mar 26, 2007 8:48 am
Location: Blue Bay (La Spezia)

Post by Alethesnake »

Good, it's exactly what I need :D

Thanks a lot for your precious help.

Bye
...
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Time to mark this thread as resolved.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Alethesnake
Participant
Posts: 56
Joined: Mon Mar 26, 2007 8:48 am
Location: Blue Bay (La Spezia)

Post by Alethesnake »

ray.wurlod wrote:Time to mark this thread as resolved.
Yes, you're right.

bye
...
Post Reply