Get Files's Modified Date & Time

<div style="text-align:justify;">Sometimes you need information of when a file is modified. These examples will show you how do that.

Examples 1 - Get and Print Modified Date & Time

Get file's modified date and time from a list of 'html' and 'txt' files.

for %%in (*.html *.txt) do (
        echo %%~tv
)

Result :


Examples 2 - Get, Parse and Print Modified Date & Time

As you can see in the example above, %%~t return a string format of the file's modified date and time. So how do we parset it into different portion that can be manipulate independently ? 

Here's the sample code to display / echo date and time separately for a number of *.xml files after they are parsed - special thanks to Andriy M for  the comprehensive guidance and solution on this problem.

SETLOCAL enabledelayedexpansion
FOR %%IN (*.xml) do (
  SET datetime=%%~tv
  SET fdate=!datetime:~0,10!
  SET ftime=!datetime:~11,8!
  echo !fdate!
  echo !ftime!
)
ENDLOCAL

Result :


References

Comments