VBA CDate function

CDate Function Description

The VBA CDate function converts an expression (variable) to Date data type.

Syntax

The syntax for the CDate function in VBA is:

1
CDate( expression )

Parameters

expression
An expression / variable that is to be converted to Date data type.

Other Notes

If the expression / variable can’t be converted to a Date, the function with return Error code 13: Type mismatch.

For formatting Dates use the VBA Format function

Example usage

The CDate function can be used in VBA code. Let’s look at some VBA CDate function examples:

1
2
3
4
5
6
7
8
9
10
11
CDate "12/10"
'Result: 2016-12-10
 
CDate "12/10/2015"
'Result: 2015-12-10
 
CDate "12.10"
'Result: 12:10:00
 
CDate "12 10"
'Result: 2016-12-10