Returns the expression converted to a date data type (Date).

expressionThe expression to evaluate and convert to a date.

* This function replaces the CVDATE function.
* This function refers to your local settings when converting to dates.
* The "expression" can be any valid date expression.
* If the expression passed to the function is outside the range of the data type being converted to, an error occurs.
* Date and time literals are recognised.
* This function does not recognise the names for the days of the week.
* If the year is not specified in the date, then the current year is used.
* You can use the CSTR function to return an expression converted to a String data type.
* For a full list of conversion functions refer to the Explicit Conversion page.
* For the Microsoft documentation refer to

Debug.Print CDate(44114)          '= "10/10/2020"  
Debug.Print CDate("4 Mar 2021") '= "04/03/2021"

Dim dtBirthday As Date
Dim sDateTime As String
sDateTime = "01/07/1977 12:00:26"
dtBirthday = CDate(sDateTime)
Debug.Print dtBirthday '= "01/07/1977 12:00:26"

dtBirthday = #1/12/2021#
Debug.Print CDate(dtBirthday) '= "12/01/2021"

dtBirthday = #12/1/2021#
Debug.Print CDate(dtBirthday) '= "01/12/2021"

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top