See Also Example
Returns the date represented by a String argument.
The argument stringexpression is a String representing a date from January 1, 100 through December 31, 9999.
If stringexpression includes only numbers separated by valid date separators DateValue also recognizes unambiguous dates that contain month names, either in long or abbreviated form. For example, in addition to recognizing 12/30/1991 and 12/30/91, DateValue recognizes December 30, 1991 and Dec 30, 1991., DateValue recognizes the order for month, day, and year according to the Short Date setting in the International section of the Microsoft Windows Control Panel.
If the year part of stringexpression is omitted, DateValue uses the current year from your computer's system date.
If stringexpression includes time information, DateValue doesn't return it. However, if stringexpression includes invalid time information (such as "89:98"), an error occurs.
The DateValue function returns a Variant This number represents a date from January 1, 100 through December 31, 9999, where January 1, 1900 is 2. Negative numbers represent dates prior to December 30, 1899. of VarType 7 (Date) containing a date that is stored internally as a double-precision number.
DateValue Function Example
The example uses the DateValue function to convert the String provided by the user to a Variant of VarType 7 (Date). The Variant is then used to determine the day of the week for the user-provided date. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Msg, RelVal, UserDate, Verb ' Declare variables.
Dim Flag, DD, MM, YY, WhatDay
Msg = "Enter a date in the form mm/dd/yyyy."
UserDate = InputBox(Msg) ' Get user input.
If Len(UserDate) <> 10 Then ' Use today's date
UserDate = Format(Now, "mm/dd/yyyy") ' if user didn't
End If ' use right format.
RelVal = DateValue(UserDate) ' Get date serial.
Select Case RelVal ' Use correct verb.
Case Is < Int(Now): Verb = " was a "
Case Is > Int(Now): Verb = " will be a "
Case Else : Verb = " is a "
WhatDay = Format(RelVal, "dddd") ' Determine day.
MsgBox UserDate & Verb & WhatDay & "." ' Display message.