Excel VBA CDate Function

VBA CDate Function: The CDate function in VBA converts an expression into a Date (or Time) data type.

Syntax

CDate (Expression)

Parameter

Expression (required) - This parameter represents the expression that that you want to convert to a Date. It can hold both date and time information.

Return

This function returns an expression after converting it into Date. It returns the text representations of dates and times that are in a recognized Excel format.

Example 1

Sub CDateFunction_Example1()
 Dim date_val As Date
 date_val = CDate("12/01/2020")
 ' date_val will return the date 12/01/2020
 Cells(1, 1).Value = date_val
 End Sub 

Output

12/01/2020

VBA CDate Function

Example 2

Sub CDateFunction_Example2()
 Dim date_val As Date
 date_val = CDate(43901)
 ' date_val will return the date 3/11/2020
 Cells(1, 1).Value = date_val
 End Sub 

Output

3/11/2020

VBA CDate Function

Example 3

Sub CDateFunction_Example3()
 Dim date_val As Date
 date_val = CDate(4.6)
 ' date_val will return the date 1/4/1900
 Cells(1, 1).Value = date_val
 End Sub 

Output

1/4/1900

VBA CDate Function