Windows Vista / 7 and later
Windows Server 2003 and later
With a little effort you can use
forfiles to get the last modified time of a specific file, seconds included:
REM "delims=" is required to avoid stripping AM/PM
for /f "delims=" %%i in ('"forfiles /m filename /c "cmd /c echo @ftime" "') do set modif_time=%%i
The value displayed is based on the local time of the computer and matches the time shown in the file properties dialog.
forfiles.exe is not available out of the box, however you can manually get the required executable. It's an old version which is part of the Windows 2000 Resource Kit. The syntax is case-sensitive and slightly different, and so is the output:
for /f %%i in ('"forfiles.exe -mfilename -c"cmd /c echo @FTIME" "') do set modif_time=%%i
Here the time value is displayed in the UTC format and is not affected by changes in time zone or daylight saving time. In this example the file was last modified at 15:33:54 (UTC).
Note You can obtain the newer
forfiles.exe version by grabbing a copy of the file from any Windows 2003 Server installation or setup media.