Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I converted some vb code to go out and get the date and time a person last logged into a domain controller. Here is the VB code.
Set objUser = GetObject("LDAP://CN=Leigh.Smith,OU=USERS,OU=XXXX01,DC=X +XX,DC=XXXX,DC=com") Set objLastLogon = objUser.Get("lastLogonTimestamp") intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPa +rt intLastLogonTime = intLastLogonTime / (60 * 10000000) intLastLogonTime = intLastLogonTime / 1440 WScript.Echo intLastLogonTime Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#
and it works so I made this conversion
use Win32::OLE; $objUser = Win32::OLE->GetObject('LDAP://CN=Leigh.Smith,OU=USERS,OU=XX +X,DC=XX,DC=XXX,DC=com'); $objLastLogon = $objUser->Get('lastLogonTimestamp'); $intLastLogonTime = $objLastLogon->HighPart * (2 ** 32) + $objLastLogo +n->LowPart; $intLastLogonTime = $intLastLogonTime / (60 * 10000000); $intLastLogonTime = $intLastLogonTime / 1440; print 'Last logon time: ' . $intLastLogonTime + #1/1/1601#;
The problem is that the last line I do not know how to add a date to seconds, I was able to do this in PHP. Not sure about Perl.

Any help will be welcomed.
Thanks

Replies are listed 'Best First'.
Re: Goofy Date and Time Think
by BrowserUk (Patriarch) on Dec 21, 2005 at 20:00 UTC

    It looks like your dealing with Microsoft FILETIME stamps in nanoseconds since 1/1/1601.

    If you pass the hi and lo parts into the following sub it will return a unix-style timestamp in seconds.

    sub filetimeToUnix{ my ( $hi, $lo ) = @_; my $nanosecs = $hi * 2**32 + $lo; return int( ($nanosecs - 116444736010000000) / 1E7 ); }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      What I ment to say is I have this product let's say it is 1134744389.41727. I think that is is seconds, but from when? That is what I ment to say. Do I add this back into 1/1/1601 and if so how can I convert 1/1/1601.

      Thanks for the help
      -How important does a person have to be before they are considered assassinated instead of just murdered?

        MS timestamps are 100 nanosecond units (1e-7) since 1 Jan, 1601.

        Unix timestamps are seconds (plus decimals?) since 1 Jan 1970.

        So to convert Unix style to MS, you add 11644473600 and multiply by 1e7.

        To go the other way you divide by 1e7, subtract 11644473600, and truncate to an integer.

        Where does the value, 1134744389.41727 come from? and what do you want to do with it?

        It appears to be a unix timestamp from a few days ago:

        print scalar localtime 1134744389.41727;; Fri Dec 16 14:46:29 2005

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      is 116444736010000000 the nanoseconds of 1/1/1601?
      I am not sure what the output is.
      nanojack
      -How important does a person have to be before they are considered assassinated instead of just murdered?
Re: Goofy Date and Time Think
by kwaping (Priest) on Dec 21, 2005 at 20:57 UTC
    Date::Calc's Add_Delta_YMDHMS function should do the trick.
Re: Goofy Date and Time Think
by strat (Canon) on Dec 22, 2005 at 09:56 UTC