Below are examples of how to create a time log of when the batch file is executed.

Creating a batch file that logs the time or date and time is helpful for logging when a batch file runs.

Echo time to file

Below are examples of how you can echo the time to a text file to create a time log.

echo Logged time = %time% %date%» log.txt

The above example will append “Logged time = 4:50:09.96 Thu 08/31/2019” to the log.txt file. We like this method of logging because it gives you the most information in a single line format.

Below are some older suggestions for earlier versions of Windows and that are submitted to us by visitors to our site.

ECHO. |TIME > TIME COPY LOG.TXT +TIME

echo. |time |find “current” » log.txt

An alternate and slightly more complicated method that may not work in all versions of Windows.

For the above batch file’s to work properly, you must create a file called log.txt. If this file is not created, you receive an error message.

echo @prompt set date=$d$_set time=$t$h$h$h > {a}.bat %comspec% /e:2048 /c {a}.bat > {b}.bat for %%v in ({b}.bat del) do call %%v {?}.bat echo %date% %time% » log

  • How to make a batch file.
  • Batch file help.