Add timestamp to log lines from batch output Add timestamp to log lines from batch output windows windows

Add timestamp to log lines from batch output


You could echo DATE% and %TIME% to backup.log.

echo %DATE% %TIME% >> E:\backup\backup.log

That's probably the easiest.

You could also use robocopy for richer logging options.


The standard variables %date%and %time% are what you are looking for.

You can pass the lines of a command output as single lines with a for-loop and in between them

@echo offfor /f "delims=" %%i in ('xcopy \\10.8.0.1\share\ E:\backup\ /c /s /r /d /y /i') do (    echo [%date%, %time%] %%i >> E:\backup\backup.log)

Short explanation: The loop splits the output of the command to the single lines. For each line the program then echos the timestamp and after that one line of the output. Then it repeats for each line getting returned by the xcopy command.