'********************************************************************
'*
'* Function WMIDateToString
'*
'* Author: NetworkAdminKB.com
'* Created: 2008-04-22
'* Modified: 2008-04-28
'*
'* Purpose: Converts WMI date and time string to a readable string.
'*
'* Input: dtmDate A WMI formated date and time.
'* 20080428081005.000000-300 = 4/28/2008 8:10:05 AM (-300 from UTC)
'* blnLocal A boolean indicating to adjust the time for local time zone.
'* True = Return Time Adjusted for Local time zone
'* False = Return un-adjusted time.
'*
'* Output: A string containing the date specified.
'* Returns Empty if Null or Empty dtmDate provided
'*
'* Notes: SWbemDateTime Requires Windows XP, 2003 or newer
'*
'* Changes:
'* 2008-04-28: Changed to use SWbemDateTime object to convert date and time.
'* This provides a more accurate time conversion.
'* 2008-04-28: Added blnLocal to allow choice in coverting to local time.
'* 2008-04-28: Added error check to support Win2000 computers.
'********************************************************************
Function WMIDateToString(ByVal dtmDate, ByVal blnLocal)
'Version 1.3 2008-04-28
Dim objSWbemDateTime
If IsNull(dtmDate) or IsEmpty(dtmDate) or dtmDate="" Then
WMIDateToString = Empty
Else
On Error Resume Next
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
If Err.Number <> 0 Then
'An error occured creating the SWbemDateTime object.
'Probably a Win2000 computer.
On Error GoTo 0
'Use the older text manipulation method, with no local time zone
'adjustment.
WMIDateToString = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & _
Left(dtmDate, 4) & " " & _
Mid(dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & _
Mid(dtmDate, 13, 2))
Else
On Error GoTo 0
objSWbemDateTime.Value = dtmDate
WMIDateToString = objSWbemDateTime.GetVarDate(blnLocal)
Set objSWbemDateTime = Nothing
End If 'Err.Number <> 0
End If 'Not IsNull(dtmDate)
End Function 'WMIDateToString