Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, May 5, 2014 3:06 PM
I wrote an Auditing tool that pulls information from Active Directory and then looks up in other database if the user has accounts. I can pull everything just fine, including the LastLogonTimeStamp. However, I am having a hard time figuring out the correct code to convert it into something that is readable such as DateTime.
Any help is much apprericiated.
All replies (3)
Monday, May 5, 2014 3:20 PM ✅Answered
"Windows 2003 stores the time stamp as 100-nano secs intervals occurred since Jan 1, 1601"
Check this thread: http://social.technet.microsoft.com/Forums/en-US/e0a2c083-6994-4b08-9f62-4420cd324491/converting-lastlogontimestamp-to-datetime?forum=identitylifecyclemanager
To convert this time stamp to a readable format, with VB.NET, you could use the Date.FromFileTime function.
Code Snippet
mventry(stringAttribute).Value = _
Date.FromFileTime(csentry("lastLogonTimestamp").Value).ToString
Example : lastLogonTimeStamp 128673223549843750 = "01/10/08 10:12:34"
Code Snippet
mventry(stringAttribute).Value = _
Date.FromFileTime(csentry("lastLogonTimestamp").Value).ToString("dd/MM/yy")
Example lastLogonTimeStamp 128673223549843750 = 01/10/08
Code Snippet
mventry("description").Value = _
Date.FromFileTime( _
csentry("lastLogonTimestamp").Value).ToString("dddd dd MMMM yyyy HH:mm:ss")
Example lastLogonTimeStamp 128673223549843750 = "wednesday 01 october 2008 10:12:34"
Tuesday, May 6, 2014 9:26 AM ✅Answered
Actually I figured out last night. Here is the code I used once i grabbed the lastLogonTimeStamp from AD
long lastLogon = (long)searchResult.Properties["lastLogonTimeStamp"][0];
string dt = DateTime.FromFileTime(lastLogon).ToString();
dr["Last Logon"] = dt.ToString();
Monday, May 5, 2014 3:16 PM
Can you provide a sample time stamp here? Then I can go to work on finding some way to convert it to mm/dd/yyyy HH:mm:ss