Page 1 of 1
Valid Date function
Posted: Thu Mar 30, 2006 1:51 pm
by kris007
Hi All,
I would like to know if there is any function available in DataStage such that
It Returns TRUE or FALSE to indicate whether a string represents a valid date in the specified format.
I have looked at the options but didn't find one. Just want to know if I missed it by any chance.
Thanks
Kris
Posted: Thu Mar 30, 2006 1:57 pm
by I_Server_Whale
I think it is 'DateGenericIsDate' transform to check for the validity of a date. But it checks only a certain number of formats.
Posted: Thu Mar 30, 2006 2:22 pm
by ray.wurlod
Not really out of the box. The SDK routine is very specific about format. The function, however, is very easy, provided you specify the format in a manner expected by Iconv() - that is, "DDMY", "DMDY" or "DYMD".
Code: Select all
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)
Validate Date Function
Posted: Mon Apr 10, 2006 12:03 pm
by avi21st
In my project I needed a routine to check whether a date is in valid format. We need to give the input format which has been specified as CCYYMMDD. I am describing the functionality and the code below. Please suggest any improvement that can be incorporated
Arguments:
Arg1 = aINDATE : Input date
Arg2 = Format of input date : aVALIDFORMAT
Called by:
Transformer
Routine Functionality:
The routine check whether the input date is in valid format.
Return Values:
0 = If the Input Date is in Valid format
1 = If the Input Date is NOT in Valid formatCode: Select all
************************************************************************
* Input Argument: Input : Input Date *
* Sformat : The Valid Date Format CCYYMMDD *
*************************************************************************
Input = aINDATE
Sformat = Upcase(aVALIDFORMAT)
Output=1
If Sformat = "CCYYMMDD" Then
Convert=Iconv(Input,"D-YMD[4,2,2]")
End
ConvStatus= Status()
*************************************************************************
* Output: 1 if there is error or warning in conversion *
* 0 if the conversion is successful *
*************************************************************************
Begin Case
Case (ConvStatus=1 or ConvStatus=2 or ConvStatus=3)
Output=1
Case ConvStatus=0
Output=0
End Case
Ans= Output