> Help with calculate the time the script took to complet

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BILL Dos
Posts: 12
Joined: 22 Sep 2009 11:49
Location: USA

> Help with calculate the time the script took to complet

#1 Post by BILL Dos » 24 Sep 2009 16:31


I am using the below script and it works good in printing out the start and end time of running my scripts
but I would also like to have it do the math and say how many minutes it took to complete etc.
If anyone has any input on this i would greatly appreciate it..

Code: Select all

@echo off

set starttime=%time%

echo All my batch files go here (about 20 minutes worth)

All Installs and Updates have completed Successfully!

echo Start Time=%starttime% - End Time=%time%

pause
start /wait restart.exe

exit

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 25 Sep 2009 09:58

You'll have to adapt this a little bit, but here's some code that I put together for this in the past:

Code: Select all

@echo off
set start=%time%
ping -n 8 127.0.0.1 >nul 2>nul
set finished=%time%
:calc
for /f "tokens=1-3 delims=:." %%a in ("%start%") do (
   set hour=%%a
   set /a minute=100%%b %% 100
   set /a second=100%%c %% 100
)
for /f "tokens=1-3 delims=:." %%a in ("%finished%") do (
   set hour2=%%a
   set /a minute2=100%%b %% 100
   set /a second2=100%%c %% 100
)

if /i %second2% lss %second% (
   set /a second2+=60
   set /a minute2-=1
)
if /i %minute2% lss %minute% (
   set /a minute2+=60
   set /a hour2-=1
)
if /i %hour2% lss %hour% (
   set /a hour2+=24
)
set /a hourd=%hour2%-%hour%
set /a minuted=%minute2%-%minute%
set /a secondd=%second2%-%second%
set /a secondsd=3600*%hourd%+60*%minuted%+%secondd%

echo %hourd% hours, %minuted% minutes, and %secondd% seconds.
echo %secondsd% total seconds.


It should work up to 24 hours (I didn't add days). It'll do hours, minutes, seconds as well as total seconds (no hundredths of seconds).

BILL Dos
Posts: 12
Joined: 22 Sep 2009 11:49
Location: USA

** Problem Fixed **

#3 Post by BILL Dos » 28 Sep 2009 15:19

Thanks avery_larry made some minor changes on your code and works great! :D

Code: Select all

@ECHO OFF

cls && Color 1E
REM | Sets date and timestamp in 12 hr format on same line |
ECHO/|set /p =%DATE%  & %TIME/t
echo.
echo.
SET USBDRIVE=
REM +==================================================+
REM |  Finding CD-ROM/DVD/USB Drive Letter for Install |
REM +==================================================+
SET TAGFILE =\win51
For %%i in (D E F G H I J K L M N) DO IF EXIST "%%i:%tagfile%" SET CDDRIVE=%%i:
if "%CDDRIVE%" == "" (FOR %%i IN (D E F G H I J K L M N) DO IF EXIST "%%i:%TAGFILE%" SET CDDRIVE=%%i:)

REM | Automates the Installation of Vista 32-bit Programs and Critical Updates. |

set start=%time%


REM    [All Batch Files go here]


echo +================================================================+
echo +      All Installs and Updates have completed Successfully!     +
echo +      Total time for all Installs and Updates...                +
echo +================================================================+

ping -n 8 127.0.0.1 >nul 2>nul
set finished=%time%
:calc
for /f "tokens=1-3 delims=:." %%a in ("%start%") do (
   set hour=%%a
   set /a minute=100%%b %% 100
   set /a second=100%%c %% 100
)
for /f "tokens=1-3 delims=:." %%a in ("%finished%") do (
   set hour2=%%a
   set /a minute2=100%%b %% 100
   set /a second2=100%%c %% 100
)
if /i %second2% lss %second% (
   set /a second2+=60
   set /a minute2-=1
)
if /i %minute2% lss %minute% (
   set /a minute2+=60
   set /a hour2-=1
)
set /a minuted=%minute2%-%minute%
set /a secondd=%second2%-%second%
set /a secondsd=3600*%hourd%+60*%minuted%+%secondd%

echo %minuted% minutes, and %secondd% seconds.
echo.
pause

restart.exe
EXIT


Post Reply