VBA CDate function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

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:

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:

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 

Simply the best place to learn VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match