Jump to content

Recommended Posts

Posted

Hi!

I want to convert given integer8 values to date and time.

I know - there are some examples reading the attributes from the ad but i need the direct convert of a value.

I found a kix code but can't translate it to autoit.

;
;Function: 
; fnInteger8Date() 
;
;Author: 
; Christopher Shilt (christopher.shilt@relizon.com) 
; ;Contributors: 
; Richard Mueller (HilltopLab@RLMueller.Net) 
; Jochen Polster (jochen.polster@gmx.net)  
; Bryce Lindsay (http://kix.isorg.com/) 
; 
;Version: 
; 1.0 (Aug 17, 2005) 
; 
;Version History: 
; 
;Action: 
; Returns the Date/Time of an Integer8 date object in YYYY/MM/DD HH:MM:SS format. 
; ;Syntax: 
; fnInteger8Date(OBJDATE, Optional BIAS) 
; 
;Parameters: 
; OBJDATE      : Required. Integer8 date object. 
; 
;BIAS         : Optional. Timezone bias to adjust the time returned for the 
;                date object. If not specified, it will use your default active 
;                timezone bias. If BIAS = 0, then it will return the UTC date/ 
;                time. 
; 
;Remarks:  
; 
; Many attributes in Active Directory have a syntax called Integer8. These 64-bit 
; numbers (8 bytes) usually represent time in 100-nanosecond intervals. If the 
; Integer8 attribute is a date, the value represents the number of 100-nanosecond 
;intervals since 12:00 AM January 1, 1601. 
; 
; ADSI automatically employs the IADsLargeInteger interface to deal with these 
; 64-bit numbers. This interface has two property methods, HighPart and LowPart, 
; which break the number up into two 32-bit numbers. The LowPart property method 
; returns values between -2^31 and 2^31 - 1. 
; 
;Returns: 
; 
; A Interger8 Date Object in YYYY/MM/DD HH:MM:SS format. 
; 
; Sets the value of @ERROR based on success/failure. 
;         
;Dependencies: 
; NONE! (Thanks, Bryce!) 
;  
;Example: 
; 
; 
; == Display the date/time the user last changed their password ==  
; $objSys = CreateObject("ADSystemInfo") 
; $objUser = GetObject("LDAP://"+$objSys.UserName) 
;   
; "You last set your password on " + fnInteger8Date($objUser.pwdLastSet) + "." ? 
; 
Function fnInteger8Date($objDate,Optional $lngBias)    
    Dim $lngHigh,$lngLow,$lngDate,$Pow,$l,$jdate,$lngYear,$lngMonth,$lngDay,$s,$m,$h   
    If Not (VarType($objDate) & 9) Exit 87 EndIf   
    If VarType($lngBias)=0
        $lngBias = Val(ReadValue("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\","ActiveTimeBias"))
        If @ERROR Exit @ERROR EndIf
    EndIf

    $lngHigh = $objDate.HighPart    
    $lngLow = $objDate.LowPart    
    If $lngLow < 0 $lngHigh=$lngHigh+1 EndIf   
    If $lngHigh = 0 And $lngLow = 0 $lngBias=0 EndIf   
    $Pow=2.0   
    For $l = 1 to 31 $Pow=2.0*$Pow Next   
    $lngDate = ((CDBL($lngHigh)*$Pow+$lngLow)/600000000-$lngBias)/1440    
    If $lngDate > 0
        $jdate = 584389 + Fix($lngDate)
        $lngYear = (100*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4))+
        (100*($jdate+306)-25))/36525
        $lngMonth = (5*(((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
        ($jdate+306)-365*$lngYear-$lngYear/4)+456)/153
        $lngDay = (((100*($jdate+306)-25)/3652425)-(((100*($jdate+306)-25)/3652425)/4)+
        ($jdate+306)-365*$lngYear-$lngYear/4)-(153*$lngMonth-457)/5
        If $lngMonth>12 $lngYear=$lngYear+1 $lngMonth=$lngMonth-12 EndIf
        $lngMonth = Right("0"+$lngMonth,2)
        $lngDay = Right("0"+$lngDay,2)
        $s = Fix(86400.0 * ($lngDate-Fix($lngDate)))
        $m = $s / 60
        $s = $s mod 60
        $h = $m / 60
        $m = $m mod 60
        $fnInteger8Date=''+$lngYear+'/'+$lngMonth+'/'+$lngDay+' '+$h+':'+Right("0"+$m,2)+':'+Right("0"+$s,2)
    EndIf
EndFunction

Link to the original website!

Thx :)

Dizzy

Posted

You can use _Date_Time_FileTimeToStr(). Just create a $tagFILETIME struct and store the low dword in "Lo" and the high dword in "Hi" and call the function. Alternatively:

#include <Date.au3>

Local $tFT = _Date_Time_GetSystemTimeAsFileTime()
Local $iInt64Date = DllStructGetData($tFT, "Hi") * 4294967296 + DllStructGetData($tFT, "Lo") 
ConsoleWrite($iInt64Date &  @CRLF)
ConsoleWrite(_Date_Time_FileTimeToStr($tFT) & @CRLF & @CRLF)

Local $tInt64 = DllStructCreate("int64")
Local $tFTFromInt64 = DllStructCreate($tagFILETIME, DllStructGetPtr($tInt64))
DllStructSetData($tInt64, 1, $iInt64Date)

ConsoleWrite(DllStructGetData($tInt64, 1) & @CRLF)
ConsoleWrite(_Date_Time_FileTimeToStr($tFTFromInt64) & @CRLF)
Posted

An alternative

#include <Date.au3>

; utc 2000/05/25 02:26:05
ConsoleWrite(Int8(126036951652030000) & @LF)
ConsoleWrite(Int8(2479543856, 29345264) & @LF)

Func Int8($iLoPart, $iHiPart = 0)
    If $iHiPart = 0 Then
        $iSecs = Int($iLoPart / 10000000)
    Else
        If $iLoPart < 0 Then $iHiPart += 1
        $iSecs = Int(($iHiPart * 2 ^ 32 + $iLoPart) / 10000000)
    EndIf
    Return _DateAdd("s", $iSecs, "1601/01/01 00:00:00")
EndFunc ;==>Int8

Posted

An alternative

#include <Date.au3>

; utc 2000/05/25 02:26:05
ConsoleWrite(Int8(126036951652030000) & @LF)
ConsoleWrite(Int8(2479543856, 29345264) & @LF)

Func Int8($iLoPart, $iHiPart = 0)
    If $iHiPart = 0 Then
        $iSecs = Int($iLoPart / 10000000)
    Else
        If $iLoPart < 0 Then $iHiPart += 1
        $iSecs = Int(($iHiPart * 2 ^ 32 + $iLoPart) / 10000000)
    EndIf
    Return _DateAdd("s", $iSecs, "1601/01/01 00:00:00")
EndFunc ;==>Int8

Great!

Thx picaxe and Authenticity

:)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...