Retrieving Current Date and Time Values

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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

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


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net