whit3fir3 Posted February 1, 2008 Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88838-solved-php-and-date-time-functions-question/ Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 If it's Unix time, then yes. Quote Link to comment https://forums.phpfreaks.com/topic/88838-solved-php-and-date-time-functions-question/#findComment-455007 Share on other sites More sharing options...
whit3fir3 Posted February 1, 2008 Author Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88838-solved-php-and-date-time-functions-question/#findComment-455013 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88838-solved-php-and-date-time-functions-question/#findComment-455016 Share on other sites More sharing options...
whit3fir3 Posted February 1, 2008 Author Share Posted February 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88838-solved-php-and-date-time-functions-question/#findComment-455032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.