VBA DateValue

DateValue Function Description

The VBA DateValue function returns a Date variable (or date serial value) for a string representing a date.

VBA DateValue Syntax

The syntax for the DateValue function in VBA is:

1
DateValue( date )

Parameters

date
A string representing a date e.g “2015-01-01”.

Example usage

Let’s look at some VBA DateValue function examples:

1
2
3
4
5
6
7
8
9
10
11
12
Dim d as Date, l as Long
 
d = DateValue("2015-01-01")
Debug.Print d
'Result: "2015-01-01"
 
l = DateValue("2015-01-01")
Debug.Print l
'Result: 42005
 
Debug.Print DateValue("2015-01-01 10:00")
'Result: "2015-01-01"