HOME
Stephen Knight
08/23/2012 08:20 PM
Time taken for batch file to execute

Type:

VBScript, Batch/Command file

Category:

Batch, Uptime, VBScript, Time
This script uses a small vbscript line to time a batch file. You can Start / Stop the timer and count how many secs, mins, hours between the two times - they can be on different days if needed and span midnight as it records date & time.

Another option is to use

If you replace the subroutines section with this it will make the date and time within a VBScript. Swap the words day( and month( to get it in mm/dd/yyyy format instead.

Hide details for Alternate subroutines to get date using VBScript as otherwise it is dependent on system date format in %date%Alternate subroutines to get date using VBScript as otherwise it is dependent on system date format in %date%
REM =======================================
REM Subroutines below here
REM =======================================
:START
call :GetDate
set start=%now%
echo START at %start%
exit /b

:END
call :GetDate
set end=%now%
echo END at %end%
exit /b

:ShowDiff
REM Call with s,n,h for seconds, mins, hours. defaults to secs
(set type=%~1)& if "%~1"=="" set type=s

echo Wscript.Echo DateDiff("%type%", #%start%#,#%end%# ) > "%temp%\timediff.vbs"
for /f %%s in ('cscript //nologo "%temp%\timediff.vbs"') do set TimeDiff=%%s
del "%temp%\timediff.vbs"
if %Type%==n set type=m
echo TIME TAKEN: %TimeDiff% %Type%
exit /b

:GetDate
REM Gets date into %now% in date/time format the VBS understands -- dd/mm/yyyy hh:mm:ss here as by default now() or date()
REM uses the built in date format which could be Mon 01-04-2012 etc.
REM You may be able to just use %date% %time:~0,8% or %Date:~4% %time:~0,8% if preferred

echo wscript.echo day(date) ^& "/" ^& month(date) ^& "/" ^& year(date) ^& " " ^& hour(time) ^& ":" ^& right(100+minute(time),2) ^&

":" ^& right(100+second(time),2) > "%temp%\now.vbs"
for /f "tokens=*" %%d in ('cscript //nologo "%temp%\now.vbs"') do (set Now=%%d)
del "%temp%\now.vbs" > NUL
exit /b
Show details for Alternative Start and End subroutines for date format including the day name:Alternative Start and End subroutines for date format including the day name:


Show details for CodeCode
Show details for ExplanationExplanation
Show details for ExamplesExamples
Hide details for AttachmentsAttachments