Page 1 of 1

Iconv and Oconv

Posted: Thu Sep 01, 2005 1:16 pm
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

Posted: Thu Sep 01, 2005 2:10 pm
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.

Posted: Thu Sep 01, 2005 2:14 pm
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.

Posted: Thu Sep 01, 2005 5:17 pm
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")

Posted: Fri Sep 02, 2005 6:02 am
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.