Description
IsDate returns True if the given String or Number value can be converted to a valid Date and returns False otherwise.
Arguments
string is a String value or expression to be tested for being convertible to a Date value. Many forms are accepted.
number is a Number value or expression to be tested for being convertible to a Date value. It can be positive, negative or fractional. It is interpreted as a number of days since December 30, 1899.
Returns
Boolean value (True or False).
Action
IsDate returns True if the given String or Number value can be converted to a valid Date and returns False otherwise. A valid Date is any date between January 1, 100 through December 31, 9999.
Typical use
If you want to convert a String value to a Date using the functions
CDate or
DateValue, use the IsDate function first to check if the conversion will succeed. See below for an example.
Examples
IsDate ("Jan 1, 1999")
Returns True.
IsDate (100)
Also returns True since the number 100 is interpreted as 100 days from Dec. 30, 1899, which is April 9, 1900.
IsDate ("Feb 29, 1999")
Returns False since 1999 is not a leap year and so the String cannot be converted to a Date.
Suppose an orders report is grouped monthly by order date. Here is a formula that returns the Date value that is extracted from the GroupName String field. If the report is a Top N report, the GroupName field can have a value "Others". This cannot be converted into a Date, and so IsDate is used to prevent an error from being generated in the call to CDate:
Local StringVar s := GroupName ({Orders.Order Date}, "monthly");
If IsDate(s) Then
CDate(s)
Else
CDate(0,0,0)
Returns the Date value May 1, 1998 if the GroupName field value is "May - 1998". Returns the null Date (a non-printing Date value) if the GroupName field value is "Others".