@echo off SETLOCAL set STARTTIME=%TIME% set CMDLINE=%* echo [%STARTTIME%] Running %CMDLINE%... set LOG=Timer.log FOR /F %%A IN ('WMIC OS GET LocalDateTime ^| FINDSTR \.') DO @SET DT=%%A set LOG_ROLLOVER="Timer_%DT:~0,8%_%DT:~8,6%.log" if exist %LOG% move %LOG% %LOG_ROLLOVER% call %CMDLINE% >> %LOG% 2>&1 :END set ENDTIME=%TIME% rem Change formatting for the start and end times for /F "tokens=1-4 delims=:.," %%a in ("%STARTTIME%") do ( set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" ) for /F "tokens=1-4 delims=:.," %%a in ("%ENDTIME%") do ( set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" ) rem Calculate the elapsed time by subtracting values set /A elapsed=end-start rem we might have measured the time inbetween days if %end% LSS %start% set /A elapsed=(24*60*60*100 - start) + end rem Format the results for output set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 if %hh% lss 10 set hh=0%hh% if %mm% lss 10 set mm=0%mm% if %ss% lss 10 set ss=0%ss% if %cc% lss 10 set cc=0%cc% set DURATION=%hh%:%mm%:%ss%.%cc% echo [%ENDTIME%] =^> Elapsed time: %DURATION% ENDLOCAL