Page 1 of 1

Valiadete date field

Posted: Wed Aug 22, 2007 8:47 am
by rajkraj
I have a sequential file,coming in with 10 columns,the 5,6,7,8 and 10 columns are date fields.All the columns 5,6,7,8 have date fields in the format of mm/dd/yyyy.But column 10 has date field coming as

Nov 30 200
Jan 01 175


So,Now i want to validate column 10 saying if date is not coming in as 'mm/dd/yyyy' than set it to Null.Can you explain me,how to do this.


Thanks

Re: Valiadete date field

Posted: Wed Aug 22, 2007 2:11 pm
by kris
Why OCONV function is there for?

Create and use a Routine

Posted: Wed Aug 22, 2007 3:23 pm
by ratuldey
You can do something like ---
1. Build a Routine say, ValidateDate(Arg1) using Iconv and Status functions (you will get their syntax in the documentation). In the Routine call Iconv with the Argument as the input date and then call Status fucntion.
2. In Transformer where you are loading the Target table column for the date, just use a derivation like -
If (ValidateDate("<inp_date>")<>0) then NULL else <inp_date>.
The Routine would return 0 if the date format is correct and as desired or else would have statuses as 1,2 which signifies there has been a problem in date conversion using Iconv.

Let me know if we were able to build the Routine and use it.

Posted: Wed Aug 22, 2007 3:24 pm
by ArndW
What is the base year for the last format? You could use ICONV() to get the components, but need to know the offset.

Code: Select all

BadInternalDate = ICONV(In.Column,'D MDY')
Month = OCONV(BadInternalDate,'DM')
Day    = OCONV(BadInternalDate,'DD')
Year   = OCONV(BadInternalDate,'DY') + EraStart
CorrectDate = FMT(Month,"2'0'R"):" ":FMT(Day,"2'0'R"):" ":FMT(Year,"4'0'R")

Posted: Wed Aug 22, 2007 4:42 pm
by ray.wurlod
Search the forum for a server version of the IsValid() function.

Posted: Wed Aug 22, 2007 4:56 pm
by kris
Searching with few key words will give you answers before you even need to think about posting the question here.

There are several date validation routines (with comments) floating around on this portal.

Here is one from Ray.

Posted: Thu Aug 23, 2007 8:03 am
by rajkraj
I am sorry,I had tried the below routine before posting this question

FUNCTION IsValidDate(TheDate, Format)
If UnAssigned(Format) Or IsNull(Format) Or UnAssigned(TheDate) Or IsNull(TheDate)
Then
Ans = @NULL
End
Else
Test = Iconv(TheDate, Format)
Ans = Not(Status())
End
RETURN(Ans)

But when i test the routine by passing 2 parameters
i.e Nov 20 200 and the format as "DMDY",it returns a 1 (which means it is a valid format).So my question was the date is a valid date ,but what i intend to test is the format should be mm/dd/yyyy.
Any suggestions on this.

Posted: Thu Aug 23, 2007 10:57 am
by kris
Iconv(DateString, "D/MDY") would convert the date in both mm/dd/yy and mm/dd/yyyy format into internal format.

So pass the value of "D/MDY" for format when you call below routine. That will do.
Equate RoutineName To 'TestRoutine'
If UnAssigned(Format) Or IsNull(Format) Or UnAssigned(TheDate) Or IsNull(TheDate)
Then
Ans = @NULL
End
Else
Test = Iconv(TheDate, Format)
Ans = Not(Status())
End
RETURN(Ans)

Posted: Thu Aug 23, 2007 12:30 pm
by rajkraj
As Suggested by Kris,i have passed the value 'D/MDY' for the parameter value Format and Date parameter as 'Nov 20 200' ,this gives an output of 1(which means the date is valid).
But my requirement is if the format of the date is other than mm/dd/yyyy than it should say,invalid date(i.e return 0).

Posted: Thu Aug 23, 2007 12:58 pm
by chulett
'D/MDY[2,2,4]' should get you closer.

Posted: Thu Aug 23, 2007 1:03 pm
by rajkraj
I Even tried D/MDY[2,2,4] in the format parameter.
But even that returns a value 1,When i pass Parameter for the TheDate field as 'Nov 20 200'.

Posted: Thu Aug 23, 2007 2:44 pm
by us1aslam1us
why don't you try the IsValid() routine Ray had suggested in his post.

Posted: Thu Aug 23, 2007 4:19 pm
by ray.wurlod
Use the function to determine that the data is valid, and

Code: Select all

InLink.TheString Matches "2N'/'2N'/'4N"
to determine that it matches your required pattern.

Posted: Fri Aug 24, 2007 9:26 am
by rajkraj
Thanks alot Ray,that worked out absolutely perfect.