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

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.


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 off
if \{%2\}==\{\} @echo Syntax: CvtFileTime FT DT&goto :EOF
set %2=Never
If "%1" EQU "0" goto :EOF
for /f "Tokens=3,4 Delims=- " %%a in ('w32tm /ntte %1') do (
 if not "%%a" EQU "(not" set %2=%%a %%b

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.