Created
August 28, 2014 14:37
-
-
Save jcefoli/57881d79aa4c7548324e to your computer and use it in GitHub Desktop.
This snippet calculates a start time, end time and total duration for your batch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO off | |
SET STARTTIME=%TIME% | |
REM DO THINGS HERE TO TIME | |
timeout 5 | |
REM DO THINGS HERE TO TIME | |
REM Final Calculations | |
SET ENDTIME=%TIME% | |
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 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 Start : %STARTTIME% | |
ECHO Finish : %ENDTIME% | |
ECHO --------------- | |
ECHO Duration : %DURATION% | |
PAUSE | |
REM Based on http://stackoverflow.com/questions/9922498/calculate-time-difference-in-batch-file |
It's 2024. Why are we not using PowerShell? This is fugly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi gweber68,
Thank for your answer!
Regards