The VBA DateValue Function

Related Function:
VBA TimeValue

Description

The VBA DateValue Function returns a VBA Date from a supplied String representation of a date. Time information within the supplied string is ignored.

The syntax of the function is:

DateValue( Date )

Where the Date argument is a valid String representation of date/time.

The DateValue function can interpret text representations of dates that are in a recognised Excel format. However, the function is unable to interpret dates that include the text description of the weekday (Sunday, Monday, etc).


VBA DateValue Function Examples

' Convert two supplied strings into dates
Dim dt1 As Date
Dim dt2 As Date
dt1 = DateValue( "12/31/2015" )
' dt1 is now equal to the date 12/31/2015
dt2 = DateValue( "Jan 1 2016 3:00 AM" )
' dt2 is now equal to the date 1/1/2016

In the above VBA code:


VBA DateValue Function Error

If the Date that is supplied to the DateValue function cannot be converted to a valid date, you will get the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box