Valid Date function

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
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Valid Date function

Post 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
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post 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.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
avi21st
Charter Member
Charter Member
Posts: 135
Joined: Thu May 26, 2005 10:21 am
Location: USA

Validate Date Function

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

Code: 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
Avishek Mukherjee
Data Integration Architect
Chicago, IL, USA.
Post Reply