JSI Tip 8079. How can I convert a long integer FILETIME, like Active Directory attributes lastLogon and pwdLastSet, to a date and time?

Jerold Schulman

May 25, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Some Active Directory date/times are stored as a long integer know as FILETIME, a count of 100 nanosecond intervals since January 01, 1601.

I have scripted CvtFileTime.bat to convert a number that represents a FILETIME, like user attributes lastLogon and pwdLastSet, to a date and time (MM/DD/YYYY HH:MM:SS).

The syntax for using CvtFileTime.bat, which must be run on Windows XP, Windows Server 2003, or later, is:

call CvtFileTime FT DT

Where FT is the FILETIME and DT is a call directed environment variable that will contain the date and time, in MM/DD/YYYY HH:MM:SS format. If FT is 0, DT will be set to Never.

Example:

If the lastLogon attribute for Jennifer contains 127299788035691693, then:

Call CvtFileTime %lastLogon% DT
@echo %DT%

would display 05/25/2004 13:13:23.

CvtFileTime.bat contains:

@echo offif {%2}=={} @echo Syntax: CvtFileTime FT DT&goto :EOFset %2=NeverIf "%1" EQU "0" goto :EOFfor /f "Tokens=3,4 Delims=- " %%a in ('w32tm /ntte %1') do ( if not "%%a" EQU "(not" set %2=%%a %%b)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like