DATEVALUE(date)

Returns the date given a string representation of a date (Date).


dateThe date you want converted (String).

REMARKS
* The "date" can be a string expression representing a date from January 1, 100 through December 31, 9999.
* The "date" can also be any expression that can represent a date, a time, or both a date and time, in that range.
* If "date" is a string that includes only numbers separated by valid date separators.
* If the year part of the date is not provided, then the current year is used.
* If "date" includes valid time information, then the time information is ignored.
* If "date" includes any invalid date or time information, then an error occurs. Type Mismatch.
* This function recognizes the order for month, day, and year according to the Short Date format you specified for your system.
* This function recognizes times according to the TIMEVALUE function.
* This function is very similar to the CDATE function.
* You can use the CDATE function to return the expression converted to a Date data type.
* You can use the DATESERIAL function to return the date given a year, month and day.
* You can use the FORMAT function to return a text string of a date in a particular format.
* The equivalent .NET function is Microsoft.VisualBasic.DateAndTime.DateValue
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print DateValue("February 12, 1969")     '= 12/02/1969  
Debug.Print DateValue("July, 19, 2021") '= 19/07/2021
Debug.Print DateValue("12/30/07") '= 30/12/2007
Debug.Print DateValue("12/30/2007") '= 30/12/2007
Debug.Print DateValue("12/30/22") '= 30/12/2022
Debug.Print DateValue("12/30/2022") '= 30/12/2022
Debug.Print DateValue("December, 30 2021") '= 30/12/2021
Debug.Print DateValue("December 30, 2021") '= 30/12/2021
Debug.Print DateValue("30 Dec, 2021") '= 30/12/2021
Debug.Print DateValue("Dec 30, 2021") '= 30/12/2021
Debug.Print DateValue("12/30/2021 12:40:13") '= 30/12/2021
Debug.Print DateValue("12/30/2021 12:90:30") 'Error 13 '90 minutes is not valid
Debug.Print DateValue("29/2/2024") 'Error 13 '2022 is not a leap year
Debug.Print DateValue("29/2/2024") 'Error 13 '2024 is a leap year

Dim lserial As Long
lserial = DateValue("12 Jul 2021")
Debug.Print lserial '= 44389

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