Page 1 of 1

Date Validation

Posted: Mon Oct 04, 2004 11:28 am
by sumitgulati
Hi All,

I am getting a 6 digit integer as my input. I have to check if the input integer is a valid date in format MMDDYY. Here is what I do:

I format the integer to get a character in the format MM/DD/YY and then use IConv on this to convert it to internal date.

Code: Select all

Arg = Substrings(Arg1,1,2):'/':Substrings(Arg1,3,2):'/':Substrings(Arg1,5,2)

Ans = Iconv(Arg, "D/MDY[2,2,2]")
Arg1 being the input integer. I expect Iconv to give error message for invalid date but it does not do that. I tried with following Arg1 values:
043102 - Since in April there are only 30 days it should report an error
023001 - Since in February only 28 days are present it should report an error

Its not working. Is there any better way of validating the date.

Regards,
Sumit

Posted: Mon Oct 04, 2004 11:32 am
by chulett
Iconv is giving you an error on dates like that, you just aren't seeing it. Check out the online help for the Status function. It (among other things) allows you to check the success or failure of a date conversion, and the online help shows you how to do that.

Posted: Mon Oct 04, 2004 11:48 am
by sumitgulati
Thanks Craig. I just went through the Status() stuff and tried that. It works perfectly fine.

Regards,
Sumit

Posted: Mon Oct 04, 2004 4:41 pm
by sumitgulati
Hi,

I wrote the following code in my transformer to validate Arg1, which is coming from the source:

Code: Select all

If 
Field(Iconv(Substrings(Arg1,5,6), "DMDY[2,2,2]"):"-":Status(),"-",2)=0 Then 'N' else 'Y'
Sample data for Arg1:
AAAA022802
AAAA022902
AAAA022904

The code works fine when put in a routine. However when the code is put into a transformer to set an ERROR_FLAG it does not accept it. It says:
Variable 'Status' not defined

Any idea why is this so? Is there any other way to perform Iconv and access the Status in Transformer Derivation?

Regards,
Sumit

Posted: Mon Oct 04, 2004 4:48 pm
by chulett
No, you had it right at first - it must be done in a Routine. That is the only way to use multiple lines of 'code'. :wink:

Posted: Mon Oct 04, 2004 4:57 pm
by sumitgulati
Consider the below code for a routine:

Code: Select all

Ans = Field(Iconv(Arg1, "DMDY[2,2,2]"):"-":Status(),"-",2)

It is just a single line code that accepts Arg1 as input.

When I put Field(Iconv(Arg1, "DMDY[2,2,2]"):"-":Status(),"-",2) in transformer I get the following error:
Variable 'Status' not defined

Regards,
Sumit

Posted: Mon Oct 04, 2004 5:14 pm
by chulett
And? :lol: Like I said, gotta do it in a routine.

Perhaps I should have said "It's the only way to use multiple lines of code or certain functions'. I'm sure Ray will be along later tonight to give us all the gory details of the Whys and the Wherefors. :wink:

Posted: Mon Oct 04, 2004 5:17 pm
by sumitgulati
Thanks Craig. I have now converted it to a routine. Lets wait and see what Ray has to say on this.

Regards,
Sumit

Posted: Mon Oct 04, 2004 6:40 pm
by dhiraj
this should be even faster :wink:

Code: Select all

Iconv(Arg1, "DMDY[2,2,2]")
Ans=status()
Dhiraj