Iconv and Oconv

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
fmartinsferreira
Participant
Posts: 142
Joined: Wed Mar 24, 2004 10:51 am
Location: Brazil

Iconv and Oconv

Post by fmartinsferreira »

I need to calculate the difference between two dates in the transformer
stage.

x = end_date - start_date

But there is some considerations:

- I need the difference in days
For example: x = 2005-05-12 - 2005-30-12
then x = 25

- the end_date is 'YYYY-MM-DD'
For example: 2005-05-12

- the start_date is 'YYMMDD' like a integer
For example: 050512 but how like a integer then 50512 because the 0 it disappears.

I'm trying to use Iconv and Oconv but I'm need help.

Can any one help me?

Regards,

Fernando Martins
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Hello Fernando,
you only need the ICONV function here; converting the EndDate is easy, just a ICONV(EndDate,'D4-YMD') will do the trick. The StartDate is somewhat moe of a challenge, as the lengths vary. I think that ICONV(FMT(StartDate,"8'0'R"),"D4DMY") should work, but I don't have a DS instance to test it on. The EndDate-StartDate will give you the difference in days.
Last edited by ArndW on Thu Sep 01, 2005 2:17 pm, edited 1 time in total.
gradkarthik
Participant
Posts: 28
Joined: Fri Jul 29, 2005 3:51 pm
Location: Arizona, USA

Post by gradkarthik »

Hi
Try this code. this should give you the date difference in days
if isnull(Iconv(Arg1[1,10],"D4Y-MD")) or isnull(Iconv(Arg2[1,10],"D4Y-MD"))
then
Ans = -1
end else
Ans = Iconv(Arg1[1,10],"D4Y-MD") - Iconv(Arg2[1,10],"D4Y-MD")
end

it takes in two arguments Arg1 is end date and arg2 is startdate.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Iconv() is an exceptionally clever function. For dates all it needs is the day month year ordering (and not even that if the date is ordered correctly for your locale).

Therefore an elegant solution is

Code: Select all

Iconv(EndDate, "DYMD") - Iconv(StartDate, "DYMD")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rumu
Participant
Posts: 286
Joined: Mon Jun 06, 2005 4:07 am

Post by rumu »

ray.wurlod wrote:Iconv() is an exceptionally clever function. For dates all it needs is the day month year ordering (and not even that if the date is ordered correctly for your locale).

Therefore an elegant solution is

Code: Select all

Iconv(EndDate, "DYMD") - Iconv(StartDate, "DYMD")
Hi,
I agree with ruy.I had used this code in my jobs.
Post Reply