Question : Batch script to calculate elapsed time in seconds : must be able to handle if time crosses midnight



time < empty.txt | find "current"
  (above will return "The current time is: 23:38:08.53" - try to capture
    this timing into a variable)
starttime=..... (capture it in seconds)
run some vb script or batch script

endtime= .....  (capture it in seconds


:calculatetimelapsed
elapsedtime=endtime - starttime

Answer : Batch script to calculate elapsed time in seconds : must be able to handle if time crosses midnight

This should calc the runtime in seconds even when passing midnight. It won't work if the vbs script runs for more than 24h
HTH
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
@echo off
For /f "delims=:,. tokens=1-3" %%a in ("%TIME%") do SET HOURS=%%a&SET MINUTES=%%b&SET SECONDS=%%c
SET /A STARTTIME=%HOURS%*3600+%MINUTES%*60+SECONDS
echo %STARTTIME%

echo Running script ...


For /f "delims=:,. tokens=1-3" %%a in ("%TIME%") do SET HOURS=%%a&SET MINUTES=%%b&SET SECONDS=%%c
SET /A ENDTIME=%HOURS%*3600+%MINUTES%*60+SECONDS
echo %ENDTIME%
If %ENDTIME% LSS %STARTTIME% SET /A ENDTIME=%ENDTIME%+86400
SET /A RUNTIME=%ENDTIME%-%STARTTIME%
echo Run time %RUNTIME% seconds
 
Random Solutions  
 
programming4us programming4us