DateValue()

Syntax

DateValue(DateText$)

Remarks

Returns the serial number of the date represented by DateText$. Use DateValue() to convert a date represented by text to a serial number. A serial number is a decimal representation of the date, time, or both. For information about serial numbers, see DateSerial().

Argument

Explanation

DateText$

A string representing a date in a Word date format. For example, the following are each valid representations of July 8, 1991:

7/8/91

July 8, 1991

8 July 1991

If DateText$ includes only numbers, DateValue() recognizes the order of the components of the date as month, day, year.


DateText$ must represent a date from December 30, 1899, to December 31, 4095. DateValue() generates an error if DateText$ is out of this range. If the year portion of DateText$ is omitted, DateValue() uses the current year from the computer's built-in calendar. DateValue() ignores time information in DateText$.

Example

This example prompts the user to enter an end date, and then displays the number of days between today and that date:


enddate$ = InputBox$("Please enter an end date:")
serialenddate = DateValue(enddate$)
numdays = serialenddate - Today()
numdays = Abs(numdays)
MsgBox "The number of days between now and " + enddate$ + \
    " is" + Str$(numdays) + "."

See Also

Date$(), DateSerial(), Now(), TimeValue(), Today()