'********************************************************************
'*
'* Function Integer8ToDate
'*
'* Author: NetworkAdminKB.com
'* Created: 2006-01-13
'* Modified: 2006-01-13
'*
'* Purpose: Returns the Date (as a Date Type) when an Object's Integer8
'* property is passed, or when the actual Integer8 number is
'* passed as a Double or String type.
'*
'* Input: anyVar An Integer8 property of an ADSI object or a number
'* (as string or Double type) with at least 7 zeros.
'* anyTZAdjust A boolean indicating to adjust for the local computer
'* Time Zone setting OR a number representing the desired
'* Time Zone setting adjustment to use, expressed in seconds.
'* True = Adjust for Time Zone (Default)
'* False = Do not adjust for Time Zone
'* Example Time Zone Adjustment Values (not a complete list)
'* 120 = GMT - 2 hours
'* 60 = GMT - 1 hour
'* 0 = GMT
'* -60 = GMT + 1 hour
'* -120 = GMT + 2 hours
'* If Empty is passed then the Default Computer Local Time Zone
'* information is used.
'*
'* Output: Returns the Date (as a Date Type) given the input value.
'* Returns the Date "1/1/1601" if no value is set or zero is passed.
'*
'* Examples:
'* Set objUser = GetObject("LDAP://cn=Administrator,cn=Users,dc=domain,dc=com")
'* Set objPwdLastSet = objUser.pwdLastSet
'* Wscript.Echo "Password last set: " & Integer8ToDate(objPwdLastSet, True)
'* Or
'* Wscript.Echo Integer8ToDate("127814175410000000", -60)
'* Wscript.Echo Integer8ToDate(0, False)
'*
'*
'* Notes: The Integer8 value is the number of 100-nanosecond intervals
'* since 12:00 AM January 1, 1601, in Coordinated Universal
'* Time (UTC). The conversion is only accurate to the nearest
'* second, so the Integer8 value will always end in at least
'* seven zeros.
'*
'* Calls:
'* DateTimeBias
'*
'********************************************************************
Function Integer8ToDate(ByRef anyVar, ByVal anyTZAdjust)
'Version: 1.0 2006-01-13
Dim lngAdjust, lngDate, lngHigh, lngLow
If Vartype(anyTZAdjust) <> 11 Then
lngAdjust = anyTZAdjust
Else
lngAdjust = DateTimeBias
'Set default if not specified.
If IsEmpty(anyTZAdjust) Then anyTZAdjust=True
'If anyTZAdjust=False Then don't adjust for TZ.
If Not anyTZAdjust Then lngAdjust=0
End If 'IsNumeric(anyTZAdjust)
If IsObject(anyVar) Then
lngHigh = anyVar.HighPart
lngLow = anyVar.LowPart
Else
lngHigh = 0
lngLow = anyVar
End If 'IsObject(anyVar)
'Account for error in IADslargeInteger
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If 'lngLow < 0
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If '(lngHigh = 0) And (lngLow = 0)
lngDate = #01/01/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
'Trap error if lngDate is extremely large.
On Error Resume Next
Integer8ToDate = CDate(lngDate)
If Err.Number <> 0 Then
On Error GoTo 0
Integer8ToDate= #01/01/1601#
Err.Clear
End If 'Err.Number <> 0
On Error GoTo 0
End Function 'Integer8ToDate