I want toconvert Nondelimited date to DS internal Format

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
december786
Participant
Posts: 14
Joined: Mon May 23, 2005 9:15 pm

I want toconvert Nondelimited date to DS internal Format

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You can perform a ICONV(In.DateString[1,4]:'-':In.DateString[5,2]:'-':In.DateString[7,2],'D4-ymd') to do this.
ram1899
Charter Member
Charter Member
Posts: 41
Joined: Wed Aug 04, 2004 11:46 am

Re: I want toconvert Nondelimited date to DS internal Format

Post by ram1899 »

what - Arnd suggested will work I have done the same in my project getting data from MainFrame

Thank you
ram1899
december786
Participant
Posts: 14
Joined: Mon May 23, 2005 9:15 pm

Post 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"
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
december786
Participant
Posts: 14
Joined: Mon May 23, 2005 9:15 pm

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
pandu80
Participant
Posts: 50
Joined: Fri Apr 08, 2005 5:56 pm

Post 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.
Precious
Charter Member
Charter Member
Posts: 53
Joined: Mon Aug 23, 2004 9:51 am
Location: South Africa
Contact:

Post 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,
Precious

Mosher's Law of Software Engineering: Don't worry if it doesn't work right. If everything did, you'd be out of a job.
december786
Participant
Posts: 14
Joined: Mon May 23, 2005 9:15 pm

Post 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
Post Reply