How to make a time and date log in a batch file

Updated: 04/26/2017 by Computer Hope

Batch fileBelow 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 time and date can be helpful for logging when a batch file performs an update or when a computer starts or performs any other action.

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 = 7:26:09.96 Thu 09/10/2015" 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 have been submitted to us by visitors to our site.


echo. |time |find "current" >> log.txt

Note: For the above batch file's to work properly, you must create a file called log.txt. If this file is not created, you will get an error message.

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

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