O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

DateValue Function

Syntax

DateValue(stringexpression)
stringexpression

Use: Required

Data Type: String expression

Any of the date formats recognized by IsDate.

Return Value

Variant of type Date.

Description

Returns a Date variant containing the date represented by stringexpression. 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 stringexpression must be the same as the sequence defined by the computer’s regional settings.

  • Only those date separators recognized by IsDate can be used.

  • If you don’t specify a year in your date expression, DateValue uses the current year from the computer’s system date.

Example

Dim dateExpression

dateExpression = #10 March 2003#

If IsDate (dateExpression) Then
     MsgBox DateValue(dateExpression)
Else
     MsgBox "Invalid date"
End If

Programming Tips and Gotchas

  • When working with dates, always check that a date is valid using the IsDate function prior to passing it as a function parameter.

  • If stringexpression includes time information as well as date information, the time information is ignored; however, if only time information is passed to DateValue, an error is generated.

  • DateValue handles two-digit years in the following manner: year arguments between ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required