Learn Excel - Simplify Life with Excel Concepts

Excel CDate Function (VBA)

CDate Function VBA Code

How to use the CDate Function (VBA)

This Excel tutorial explains how to use the Excel CDate function with syntax and examples using VBA.

SUMMARY:

The Excel VBA CDate function converts an expression into a Date data type.

For example,

  • The VBA Code CDate("12/30/2017") would return 12/30/2017
  • The VBA Code CDate( "Feb 1 2018") would return 2/1/2018

PURPOSE:

To converts a value to a Date.

RETURN VALUE:

The CDate function returns a Date value.

SYNTAX:

CDate( expression )

ARGUMENTS:

The CDate function syntax has the following arguments:

  • expression: Required. The expression is that you want to convert to a Date data type.
    • The "expression" can be any valid date expression.
    • The "expression" must be able to be interpreted as a valid VBA date or time.

REMARKS:

  • The CDate function can only be used in VBA code in Microsoft Excel.
  • The VBA Date data type holds both date and time information.
  • The CDate function can interpret text representations of dates and times that are in a recognised Excel format.
  • The CDate function is unable to interpret dates that include the text description of the weekday (Sunday, Monday, etc).
  • If the year is not specified in the date, then the current year is used.
  • The CDate function refers to your local settings when converting to dates.

Useful Links: Link 1Link 2Link 3Link 4