DateDifference

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
prasanna2100
Participant
Posts: 36
Joined: Mon Mar 27, 2006 12:23 am
Location: Chennai

DateDifference

Post by prasanna2100 »

is there any built in function to find the date difference of two DATE values
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

As you are using Server Edition, you can use IConv. Search for it.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard. :D

The Iconv() function itself does not calculate the date difference - it converts the date into DataStage internal format, which is the number of days from a particular day zero (31 Dec 1967). It follows that, if you subtract internal format dates, you get the difference in days.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Re: DateDifference

Post by dprasanth »

prasanna2100 wrote:is there any built in function to find the date difference of two DATE values
You can use the internal conversion as
Iconv(date1,"D/DMY") - Iconv(date2,"D/DMY")
prasanna2100
Participant
Posts: 36
Joined: Mon Mar 27, 2006 12:23 am
Location: Chennai

Post by prasanna2100 »

thanks for ur reply .but i need the result to be in YEARS
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

prasanna2100 wrote:thanks for ur reply .but i need the result to be in YEARS
Why don't you try this
(Iconv(date1,"D/DMY") - Iconv(date2,"D/DMY"))/365

When you do Iconv(date1,"D/DMY") - Iconv(date2,"D/DMY"), you will get the diff in days, so divide it by 365,which will give you years
prasanna2100
Participant
Posts: 36
Joined: Mon Mar 27, 2006 12:23 am
Location: Chennai

Post by prasanna2100 »

great yaar its working !!

since my date is already in Internal format ,i just need to subtract it and convert it to years.

but y DS doesn't have a built in date diff function as all other ETL tools have.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

Yeah, try that with a number of leap years in between and post your result. :wink:

gateleys
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

Oh! Didn't notice that you only wanted number of years. In that case, never mind my previous post, you are fine.

gateleys
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

Considering gateleys observation about leap years, what you must do is first extract the year portion of each date, and then subtract.

Also, consider how your application treats fractional year differences; do you 'round-up' or 'round-down'?

As for the built-in date difference function, since DataStage keeps dates as an internal number type, it's already there ( the minus sign ).

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

Post by ray.wurlod »

Code: Select all

YearsDiff = Int(DaysDiff / 365.249) 
is close enough to account for leap years in most cases.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Hi,

Try following formula:

Oconv((Iconv(Arg1[1,10],"D/MDY") - Iconv(Arg2[1,10],"D/MDY")),"D2 Y") - 67


This may help you out:

Thanks,

Anupam
akarmarkar@smart-bridge.co.in
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

Or more directly:

Ans = Oconv(Iconv(Arg1[1,10],"D/MDY"),"D4Y") - Oconv(Iconv(Arg2[1,10],"D/MDY")),"D4Y")


Carter
Post Reply