Working with Dates in WMI
(Page 1 of 5 )
As you begin scripting with WMI, you will quickly learn that WMI uses its own date and time format. In order to build queries in WMI you will need an understanding of this date and time format as well as a knowledge of how to convert between WMI dates and traditional VBScript dates.
WMI uses the CMI_Datetime format, commonly referred to as simply datetime. On the surface, the datetime format is a string representation of a given date and time. Like the VBScript’s VT_Date format, this is local to the current system. Let’s take a look at an example.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
Wscript.Echo objOperatingSystem.InstallDate
Next
This simple WMI script returns the date that the current operating was installed.
20080213195848.000000-300
At first glance, this script’s output is a bit ambiguous. In fact, it looks almost cryptic. But deciphering the datetime format is really not as hard as it might seem.
Next: The Datetime format >>
More Windows Scripting Articles
More By Nilpo