Export (0) Print
Expand All

Retrieving Current Date and Time Values

Microsoft® Windows® 2000 Scripting Guide

The ability to determine the current date or the current time is a useful task in system administration scripting. Many scripts, including those that write to log files or those that write to databases, need to include the current date or time as part of the data written. Scripts that need to take action on specific days or at specific times need to be able to determine the current date and time. Scripts designed to work with a range of dates (for example, retrieve all the error events written to the event log in the past two weeks) need to be able to identify the current date or time to use as a starting point.

VBScript includes three functions that can be used to identify the current date, the current time or both:

  • Now - retrieves both the date and the time.

  • Date - retrieves the current date.

  • Time - returns the current time.

For example, the following script retrieves date and time information by using Now, Date, and Time and then displays the results of all the functions in a single message box:



DateInfo = DateInfo & Now & VbCrLf
DateInfo = DateInfo & Date & VbCrLf
DateInfo = DateInfo & Time & VbCrLf
Wscript.Echo DateInfo

When the preceding script runs, a message box similar to the one shown in Figure 2.12 appears.

Figure 2.12 Date and Time Information by Using Now, Date, and Time Functions

sas_vbs_13s
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft