Name
DateValue Function
Syntax
DateValue(stringexpression)-
stringexpression Use: Required
Data Subtype: String expression
Any of the date formats recognized by
IsDate.
Return Value
Variant of subtype Date.
Description
Returns a date variant containing the date represented by
stringexpression. The date value is
formatted according to the short date setting defined by the Regional
Settings applet in the Control Panel. DateValue
can successfully recognize a
stringexpression in any of the date
formats recognized by IsDate.
DateValue doesn’t return time values in a
date/time string; they are simply dropped. However, if
stringexpression includes a valid date
value but an invalid time value, a runtime error results.
Rules at a Glance
The order of the day, the month, and the year within
stringexpressionmust be the same as the sequence defined by the computer’s regional settings.Only those date separators recognized by
IsDatecan be used.If you don’t specify a year in your date expression,
DateValueuses the current year from the computer’s system date.
Example
Dim sDateExpression
sDateExpression = 10 & "/" & "March" & "/" & 1998
If IsDate(sDateExpression) Then
Msgbox DateValue(sDateExpression)
Else
Msgbox "invalid date"
End IfProgramming Tips & Gotchas
When working with dates, always check that a date is valid using the
IsDatefunction prior to passing it as a function parameter.If
stringexpressionincludes time information as well as date information, the time information is ignored; however, if only ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access