Jump to content

[SOLVED] PHP and Date / Time Functions Question...


whit3fir3

Recommended Posts

I am working some a project for work that queries a Microsoft Active Directory server and get some information.  One of the things it gets is lastLogon which is stored in some long integer serialized date time format.  Is there a way with PHP to convert from ntte format (aka said long integer) to something more human readable?

 

Thanks,

 

whit3fir3

Link to comment
Share on other sites

If it's Unix time, then yes.

 

Well the time value I am getting it stored in a Microsoft Active Directory Server, however my web server is a RHEL 5 linux box.  I know I could run w32tm.exe if my web server was on a windows server but is there any way to convert it on a Linux/Unix system?

 

Thanks,

 

whit3fir3

Link to comment
Share on other sites

I found this in the comments on the PHP site, no idea if it works...

 

26-Jan-2006 09:43

LDAP Active Directory Last Logon (lastlogon).

 

This took me an entire day to work out. If you want to get the last logon date from an active directory account, you have to convert it from AD time stamp to unix time stamp.

Once you've got a unix time stamp, PHP can format it as a date.

 

Here is the code to do it:

 

        $dateLargeInt=$info[$i]["lastlogon"][0]; // nano seconds (yes, nano seconds) since jan 1st 1601

        $secsAfterADEpoch = $dateLargeInt / (10000000); // seconds since jan 1st 1601

        $ADToUnixConvertor=((1970-1601) * 365.242190) * 86400; // unix epoch - AD epoch * number of tropical days * seconds in a day

        $unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor); // unix Timestamp version of AD timestamp

        $lastlogon=date("d-m-Y", $unixTsLastLogon); // formatted date

Link to comment
Share on other sites

I would say that it is close, but not exact.  I plugged it in and the date look right but I added time values in to the unix date conversion and it shows people logging into their systems at 2am in the morning.  I will go through the math equations tomorrow and see if I can find a mistake in the formula.  Either way this was a big help and a step in the right direction.

 

Thanks,

 

whit3fir3

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.