Display datetime (VBScript)

This code can be found in Chapter 2 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code displays the local date, time and time zone on a target computer
' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strComputer = "."   ' e.g. rallen-srv01
' ------ END CONFIGURATION ---------
WScript.Echo "Current time using Now function: " 
WScript.Echo vbTab & Now

set dicDaysOfWeek = CreateObject("Scripting.Dictionary")
dicDaysOfWeek.Add 0, "Sun"
dicDaysOfWeek.Add 1, "Mon"
dicDaysOfWeek.Add 2, "Tue"
dicDaysOfWeek.Add 3, "Wed"
dicDaysOfWeek.Add 4, "Thu"
dicDaysOfWeek.Add 5, "Fri"
dicDaysOfWeek.Add 6, "Sat"

set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objDateTime = objWMI.Get("Win32_Localtime=@")
WScript.Echo "Current time using WMI: "
WScript.Echo vbTab & dicDaysOfWeek.Item(objDateTime.DayOfWeek) & " " & _
         objDateTime.Month & "/" & objDateTime.Day & "/" & _
         objDateTime.Year & " " & objDateTime.Hour & ":" & objDateTime.Minute
WScript.Echo "Time zone:"
set colTZ = objWMI.ExecQuery("select * from Win32_TimeZone")
for each objTZ in colTZ
    Wscript.Echo vbTab & objTZ.Caption
next

This code has been viewed 6748 times.

New from the creators of TechTasks.com: StatSheet.com