Information.IsDate Method (Object)

 

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

Namespace:   Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static bool IsDate(
	object Expression
)

Parameters

Expression
Type: System.Object

Required. Object expression.

Return Value

Type: System.Boolean

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

IsDate returns True if Expression is of the DateTime data type or can be converted to it; otherwise, it returns False.

The DateTime 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.

The following example uses the IsDate function to determine if several variables represent valid DateTime 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.

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Return to top
Show: