When working with Date/Time functions in the WMI environment, we need to remember that this data is given to us in UTC time. For example, the date 2/25/2008 10:07:08 PM is formatted as 20080225220708.000000-300. Below is a function that will translate this UTC time into the conventional formatting for date/time. The time being feed is the OS installation date/time for the client running the script.
strComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOS = objSWbemServices.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOS in colOS
Wscript.echo WMIDateStringtoDate(objOS.InstallDate)
Next
Function WMIDateStringToDate(dtmInstallDate)
WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
& " " & Mid (dtmInstallDate, 9, 2) & ":" & _
Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
13, 2))
End Function
Comments