Last Updated on January 11, 2023 by token
1. CDate VBA Function – Description
The CDate VBA function returns a value with the Date data type . The Date data type is 8 bytes in memory. The function converts the date and time saved in text form to VBA formatted date and time. The function works like the VBA DateValue and VBA TimeValue functions when replacing text with a date . The difference is that CDate can return both date and time.
2. VBA CCur function – Syntax
CDate (Expression) As Date
Expression : Date and time saved as text e.g. 25-12-2018, 1 March 2018, 2018-05-19.
Function return : Date / Date and time
3. VBA CDate function – Example
How to use CDate function in VBA Excel? Below are examples of using the CDate function in the VisualBasic Editor.
Example 1 : Example of VBA CDate Function – result in the MsgBox window. Text on VBA date and time.
Dim strValue As String strValue = "March 1, 2018 1:5:15 am" Range ("A1") = CDate (strValue)
Example 2 : Example of VBA CDate Function – result in the MsgBox window. Convert text to date and time.
Dim strValue As String strValue = "March 1, 2018 1:5:15 am" Range ("A1") = CDate (strValue)
4. VB CDate function – Additional information
- The function can take various time or date and time formats as an argument, e.g. “1: 5:15”, or # 12/28/2017 11:15:55 AM #, 25-12-2018, March 1, 2018, May 5, 2018 19.
- Unlike the DateValue and TimeValue functions , it converts text to a date and time at the same time.
5. CDate VisualBasic function – Where to use?
The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365.
The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions .