Page 1 of 1

I want toconvert Nondelimited date to DS internal Format

Posted: Thu May 26, 2005 9:59 am
by december786
My Input date is in the format YYYYMMDD, it is non delimited, I am trying to validate the input date with the DS Transform DateGenericIsDate, but this transform will accept the date in the DS internal format, so I am trying to convert the input date(YYYYMMDD) into DS internal format using DS transform DateGenericToInternal, but this DSTransform is not converting successfully.
Please suggest what I can do.

Posted: Thu May 26, 2005 10:10 am
by ArndW
You can perform a ICONV(In.DateString[1,4]:'-':In.DateString[5,2]:'-':In.DateString[7,2],'D4-ymd') to do this.

Re: I want toconvert Nondelimited date to DS internal Format

Posted: Thu May 26, 2005 11:01 am
by ram1899
what - Arnd suggested will work I have done the same in my project getting data from MainFrame

Thank you

Posted: Thu May 26, 2005 11:46 am
by december786
Please find the condition in which I tried,

If Not(DateGenericIsDate(ICONV(In.DateString [1,4]:'-': In.DateString [5,2]:'-': In.DateString [7,2],'D4-ymd') )) Then "ED001" Else " OK"


The value of In.DateString is 20050501, the result should be "OK" but I am getting "ED001"

Posted: Thu May 26, 2005 11:53 am
by ArndW
Well, you need to see what the routine DateGenericIsDate() does; I don't know what sort of date it expects as an input, but the ICONV() function I gave you returns an integer internal date - which is what you asked for.

Posted: Thu May 26, 2005 12:27 pm
by ray.wurlod
Nah, it's easier than any of that because Iconv() is really clever. All you need is

Code: Select all

Iconv(InLink.TheDate, "DYMD")

Posted: Thu May 26, 2005 12:59 pm
by december786
Yes, I think there is some problem with the DSTransform DateGenericIsDate.Even I am trying the following condition, it is returning ED001.
If Not(DateGenericIsDate(Date() )) Then "ED001" Else " OK"

Can anyone please give me some idea to validate a YYYYMMDD string.To check whether it is correct date or not.

Posted: Fri May 27, 2005 1:47 am
by ArndW
december786,

if you want a 1-liner you could use

Code: Select all

IF(ICONV(InLink.TheDate, "DYMD")=InLink.TheDate)THEN 'Bad Date' ELSE 'Good Date'
This is because an unsuccessful ICONV/OCONV returns the original string. It is much better to use a short routine and get the value of STATUS() to find out why a conversion didn't work.

I did find the DateGenericIsDate transform (I had looked at the routines, but not the transforms) and it expects a string input date, not a DataStage internal format one; thus it is working just as expected.

Posted: Fri May 27, 2005 5:10 am
by pandu80
You can check your input date is valid or not by using

If Oconv(Oconv(Iconv(Link.InputDate,"DYMD"),"DYMD"),"MCN")=Link.InputDate Then 'GOOD DATE' Else 'BAD DATE'


HTH.

Posted: Fri May 27, 2005 5:33 am
by Precious
Just had to point out,

If you look at the underlying routine, namely DateGenericToTimeStamp, it is not expecting date in the DS internal format, it is expecting iether a julian date, or one of several date formats, CCYYMMDD being one.

I did the following in a routine, and it works fine:

Code: Select all

      Deffun isDate(x,y) Calling "DSX.DATEGENERICTOTIMESTAMP"
      If isDate(Arg1,1)="" Then
         Ans=@False
      End
      Else
         Ans=@True
      End
Regards,

Posted: Fri May 27, 2005 8:09 am
by december786
Thanks for all the suggestions.
I did this way,

If UnAssigned(Arg1) Or IsNull(Arg1)
Then
Ans = @NULL
End
Else
If Arg1 Matches "8N"
Then
Test = Iconv(Arg1, "D4YMD") ;
If Status() = 0
Then
Ans = @TRUE ;
End
Else
Ans = @FALSE ;
End
End
Else
Ans = @FALSE ;
End
End