VBScript DateValue Function
Definition and Usage
The DateValue function can return a date type.
That is to say,The DateValue function can retrieve a date from an expression.
Note:If the year part of the date is not omitted, the function will use the current year from the computer system's date.
Note:If the date parameter contains time information, the time information will not be returned. If the date contains invalid time information, a run-time error will occur.
Note:If the parameter does not contain a date, the DateValue function will return 0, and the output will be 12:00:00 AM, which is 0.
Syntax
DateValue(date)
Parameter | Description |
---|---|
date | Required. A date between January 1, 100 AD and December 31, 9999 AD, or any expression that can represent a date, time, or both. |
Instance
Example 1
document.write(DateValue("31-Jan-02"))
Output:
1/31/2002
Example 2
document.write(DateValue("31-Jan")) 'Assuming the year is 2002, the output is the year of the system date.
Output:
1/31/2002
Example 3
document.write(DateValue("31-Jan-02 2:39:49 AM")) If the parameter contains both date and time, only the date is output.
Output:
1/31/2002
Example 4
document.write(DateValue("2:39:49 AM")) 'Output 12:00:00 AM, equivalent to 0.
Output:
12:00:00 AM