CDATE

CDATE(expression)

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


expressionThe expression to evaluate and convert to a date.

REMARKS
* This function replaces the CVDATE function.
* This function uses 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.
* You can use the DATE Function to return the current system date.
* For a full list of conversion functions refer to the Explicit Conversion page.
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print CDate(45614)          '= "18/11/2024"  
Debug.Print CDate("4 Mar 2024") '= "04/03/2024"

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

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

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

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