Udostępnij za pośrednictwem


IsDate Function (Visual Basic)

Returns a Boolean value indicating whether an expression represents a valid Date value.

Public Function IsDate(ByVal Expression As Object) As Boolean

Parameters

  • Expression
    Required. Object expression.

Remarks

IsDate returns True if Expression is of the Date Data Type or can be converted to Date; otherwise, it returns False.

The Date data type holds both a date value and a time value. IsDate returns True if Expression represents a valid date, a valid time, or a valid date and time.

Example

The following example uses the IsDate function to determine if several variables represent valid Date values.

Dim firstDate, secondDate As Date 
Dim timeOnly, dateAndTime, noDate As String 
Dim dateCheck As Boolean
firstDate = CDate("February 12, 1969")
secondDate = #2/12/1969#
timeOnly = "3:45 PM"
dateAndTime = "March 15, 1981 10:22 AM"
noDate = "Hello"
dateCheck = IsDate(firstDate)
dateCheck = IsDate(secondDate)
dateCheck = IsDate(timeOnly)
dateCheck = IsDate(dateAndTime)
dateCheck = IsDate(noDate)

In the preceding example, IsDate returns True for the first four calls and False for the last call.

Requirements

Namespace: Microsoft.VisualBasic

Module: Information

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

IsArray Function (Visual Basic)

IsDBNull Function

IsError Function

IsNothing Function

IsNumeric Function (Visual Basic)

IsReference Function

Object Data Type

Date Data Type (Visual Basic)

TypeName Function (Visual Basic)