IsDate Function

Description

Returns a Boolean value indicating whether an expression can be converted to a date.

Syntax

IsDate(expression)

The expression argument can be any date or string expression recognizable as a date or time.

Remarks

IsDate returns True if the expression is a date or can be converted to a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.

See Also

CDate Function, Date Data Type, IsArray Function, IsEmpty Function, IsError Function, IsMissing Function, IsNull Function, IsNumeric Function, IsObject Function, TypeName Function, Variant Data Type, VarType Function.

Example

This example uses the IsDate function to determine if an expression can be converted to a date.


MyDate = "February 12, 1969": YourDate = #2/12/69#: NoDate = "Hello"= IsDate(MyDate)            ' Returns True.= IsDate(YourDate)        ' Returns True.= IsDate(NoDate)            ' Returns False.

The following example prompts the user for a string value, uses the IsDate function to determine whether the string can be converted to a date, and then displays an appropriate message.


Sub CheckDate()
    strDate = InputBox("Enter string to display as a date.")
    ' Test variable.
    If IsDate(strDate) Then
        ' If string is date, format and display in dialog.
        MsgBox "The date is: " & Format(DateValue(strDate), "Long Date")
    Else
        MsgBox "The value you entered is not a date."
    End IfSub