VBScript Date Function

Definition and Usage

The Date function can return the current system date.

Syntax

Date

Tips and Comments

Important Matters:

If Date, Time, and Now are read at the same time, then Now = Date + Time. However, it is impossible to call all three functions simultaneously, as one function must be executed before the other. Therefore, if you need to obtain the current date and time simultaneously in your program, you must call Now first and then use DateValue and TimeValue to extract the date and time separately.

Example: Obtain the date and time of a specific time point:

N = Now 'the date and time of this time point
D = Datevalue(N) 'the date part of the same time point
T = TimeValue(N) 'the time part of the same time point
D2 = Date 'time point 1's date
T2 = Time 'time point 2's time

Problem Thinking

What is the maximum possible error when executing Response.write Now and Response.Write Date + Time continuously? Assumptions:

The Now obtained from 'time point 1' = #7/1/95 23:59:59#
The Date obtained from 'time point 2' = #7/1/95#

And if the 'time point 3' just crosses a day, then Time = #0:00:00, so the difference between Now and Date+Time becomes 23:59:59.

Example

Example 1

document.write("The current system date is: ")
document.write(Date)

Output:

The current system date is: 1/14/2002

Try It Yourself

Date
How to use the Date function to display the current date.