Last Updated on January 11, 2023 by token
1. VBA DateValue Function – Description
The DateValue VBA function converts a text date into a formatted VBA date. The function is also used to extract the date value itself from a date and time value. If we would like to convert the time saved as text to serial time, we should use the VBA TimeValue function .
2. VBA DateValue function – Syntax
DateValue (Date As String)
Date : Date saved as text e.g. 25-12-2018, 1 March 2018, 2018-05-19.
Function return: Date / Serial date.
3. VBA DateValue function – Example
How to use DateValue function in VBA Excel? Below is an example of using the DateValue function in the VisualBasic Editor.
Example 1 : DateValue VBA – text to date. The result in the MsgBox window.
Dim datVal As Date datVal = DateValue ("1-1-2018") MsgBox datVal MsgBox DateValue ("January 1, 2019")
Example 2 : VBA DateValue – text conversion to date. The result in the worksheet cells.
Dim datVal As Date datVal = DateValue ("1-1-2018") Range ("A1") = DateValue (datVal) Range ("A2") = DateValue ("January 1, 2019")
Example 3 : VBA DateValue – extracting date from date and time.
Dim datVal2 As Date datVal2 = # 12/28/2017 11:15:55 AM # MsgBox DateValue (datVal2) Range ("A3") = DateValue (datVal2) Range ("A4") = DateValue (Now ())
4. VB DateValue function – Additional information
- The function can accept various date formats as an argument, e.g. 25-12-2018, 1 March 2018, 2018-05-19.
- The function is also used to extract the value of the date itself from the date and time.
5. DateValue 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 .