I know that exists, but is there a way to do this without any kit utility?
Main Topics
Browse All TopicsHi guys, does anybody know how to calculate the running time of a batch file. I would like to capture the starting time
and run some commands. After finishing the commands I get another evironment time variable.
Now my problem is to calculate the difference between the starting time and ending_time.
Please help me. The code skeleton is below.
The batch file looks like this:
echo Off
rem capturing the starting time
SET start_time=%time%
echo starting at %start_time% >> log.txt
rem here i want to put the batch file commands
.......
rem end of commands
rem capturing the end time and calculate the elapsed time of the commands
SET ending_time=%time%
echo ending at %ending_time% >> log.txt
rem now i need to calculate the differences between starting_time and ending_time to get the elapsed time
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Assuming I use the 2000 resource kit.
Now I am putting a loop into a bat file like the following just to make the computer work for a while.
rem commands.bat:
SET counter=0
goto LOOP
:LOOP
SET /a counter=%counter%+1
if 1000 == %counter% (
GOTO EXIT
)
GOTO LOOP
:EXIT
rem end commands.bat
How can I use the timethis method to just get elapsed time output to a log.txt file?
I assume that I am able to call the commands.bat file like
timethis "command.bat >> log.txt"
But the problem is that I do not want starting time and endtime in the log, just the elapsed time.
Thank you soo much for any clue. And also let me know if my task does not make any sense:)
the resource kit seems to be pretty cool, just to clarify my problem.
The following bat file contains:
timethis.exe commands.bat >> log.txt
this redirects all the loop steps in the command.bat file to the log.txt file.
And the last part contains the timethis information. This is the last part of the log.txt file for one run:
C:\Documents and Settings\Chris\Desktop\tim
C:\Documents and Settings\Chris\Desktop\tim
C:\Documents and Settings\Chris\Desktop\tim
C:\Documents and Settings\Chris\Desktop\tim
C:\Documents and Settings\Chris\Desktop\tim
TimeThis : Command Line : commands.bat
TimeThis : Start Time : Sun Apr 30 19:22:12 2006
TimeThis : Command Line : commands.bat
TimeThis : Start Time : Sun Apr 30 19:22:12 2006
TimeThis : End Time : Sun Apr 30 19:22:14 2006
TimeThis : Elapsed Time : 00:00:02.187
My question is, how can I just get the elapsed time to the log file and not all the other stuff.
Please help:)
Hi,
you may take a look at this thread and use something similar:
http://www.experts-exchang
about the question from your last posting - "how can I just get the elapsed time to the log file and not all the other stuff"
1) you may try to use "echo off/on" in the beginning/end of your batch file
2) you may see the help about FOR command in Windows 2000 command prompt window. There are ways to parse some info from a file
I tried several different ways with echo Off, echo On.
I am having the command.bat file containing a loop to spent some time.
This bat file is called from another .bat file containing the timethis command like this:
echo On
rem test.bat
timethis "commands.bat >> log.txt"
rem commands.bat
echo Off
SET counter=0
goto LOOP
:LOOP
SET /a counter=%counter%+1
if 1000 == %counter% (
GOTO EXIT
)
GOTO LOOP
:EXIT
echo On
playing around with the echo off or on i get either no output at all in the log.txt or all the not needed commands.
How can i just extract the elapsed time from the file?
Thank you welkin, I need to recheck my algorithm there might be still a flaw in there.
But your url link brought me to the idea to calculate the elapsed time without any resource kit. Finding
specific parts in the file, particular the elapsed time part using the timethis function would be even harder i guess.
Here is what i have to far:
Set start_time=%time%
echo Off
SET start_time=%time%
echo starting at %start_time% >> log.txt
rem here put all the commands
rem the for loop simulates the commands I want to clock
SET counter=0
goto LOOP
:LOOP
SET /a counter=%counter%+1
if 1000 == %counter% (
GOTO EXIT
)
GOTO LOOP
:EXIT
rem end of commands
SET ending_time=%time%
echo ending at %ending_time% >> log.txt
rem initialize variables, have to make sure that we work with integers, get rid of leading zero's
SET start_Hr=%start_time:~1,1%
SET start_Min=%start_time:~3,2
SET start_Sec=%start_time:~6,2
SET start_Mil=%start_time:~9,2
SET end_Hr=%ending_time:~1,1%
SET end_Min=%ending_time:~3,2%
SET end_Sec=%ending_time:~6,2%
SET end_Mil=%ending_time:~9,2%
rem verifying start_time
if 0 == %start_time:~0,1% (
SET start_Hr=%start_time:~1,1%
)
if 0 == %start_time:~3,1% (
SET start_Min=%start_time:~4,1
)
if 0 == %start_time:~6,1% (
SET start_Sec=%start_time:~7,1
)
if 0 == %start_time:~9,1% (
SET start_Mil=%start_time:~10,
)
echo text >> log.txt
rem verifying ending_time
if 0 == %ending_time:~0,1% (
SET end_Hr=%ending_time:~1,1%
)
if 0 == %ending_time:~3,1% (
SET end_Min=%ending_time:~4,1%
)
if 0 == %ending_time:~6,1% (
SET end_Sec=%ending_time:~7,1%
)
if 0 == %ending_time:~9,1% (
SET end_Mil=%ending_time:~10,1
)
rem initialize output variables
SET out_Min=0
SET out_Sec=0
SET out_Mil=0
SET remainder=0
rem calculating difference
if %end_Mil% gtr %start_Mil% (
Set /a out_Mil=%end_Mil%-%start_M
)
if %start_Mil% gtr %end_Mil% (
Set /a out_Mil=100-%start_Mil%+%e
Set remainder=1
)
if %end_Sec% gtr %start_Sec% (
Set /a out_Sec=%end_Sec%-%start_S
Set remainder=0
)
if %start_Sec% gtr %end_Sec% (
Set /a out_Sec=60-start_Sec%+%end
Set remainder=1
)
if%end_Min% gtr %start_Min% (
Set /a out_Min=%end_Min%-%start_M
Set remainder=0
)
if %end_Min% gtr %start_Min% (
Set /a out_Min=60-start_Min%+%end
Set remainder=1
)
if%end_Hr% gtr %start_Hr% (
Set /a out_Hr=%end_Hr%-%start_Hr%
)
if %end_Min% gtr %start_Min% (
Set /a out_Sec=24-start_Hr%+%end_
)
echo elapsed time %out_Hr%:%out_Min%:%out_Se
I thought this little tool comes handy
Ok, here is my final version. If still any bucks, please let me know:)
Thank you again for the help, was fun figuring this out here.
Here it is:
echo Off
SET start_time=%time%
echo starting at %start_time% >> log.txt
rem here put all the commands
SET counter=0
goto LOOP
:LOOP
SET /a counter=%counter%+1
if 100000 == %counter% (
GOTO EXIT
)
GOTO LOOP
:EXIT
rem end of commands
SET ending_time=%time%
echo ending at %ending_time% >> log.txt
rem initialize variables, have to make sure that we work with integers, get rid of leading zero's
SET start_Hr=%start_time:~1,1%
SET start_Min=%start_time:~3,2
SET start_Sec=%start_time:~6,2
SET start_Mil=%start_time:~9,2
SET end_Hr=%ending_time:~1,1%
SET end_Min=%ending_time:~3,2%
SET end_Sec=%ending_time:~6,2%
SET end_Mil=%ending_time:~9,2%
rem verifying start_time
if 0 == %start_time:~0,1% (
SET start_Hr=%start_time:~1,1%
)
if 0 == %start_time:~3,1% (
SET start_Min=%start_time:~4,1
)
if 0 == %start_time:~6,1% (
SET start_Sec=%start_time:~7,1
)
if 0 == %start_time:~9,1% (
SET start_Mil=%start_time:~10,
)
rem verifying ending_time
if 0 == %ending_time:~0,1% (
SET end_Hr=%ending_time:~1,1%
)
if 0 == %ending_time:~3,1% (
SET end_Min=%ending_time:~4,1%
)
if 0 == %ending_time:~6,1% (
SET end_Sec=%ending_time:~7,1%
)
if 0 == %ending_time:~9,1% (
SET end_Mil=%ending_time:~10,1
)
rem initialize output variables
SET out_Min=0
SET out_Sec=0
SET out_Mil=0
SET remainder=0
rem calculating difference
if %end_Mil% gtr %start_Mil% (
Set /a out_Mil=%end_Mil%-%start_M
)
if %start_Mil% gtr %end_Mil% (
Set /a out_Mil=100-%start_Mil%+%e
Set remainder=1
)
if %end_Sec% gtr %start_Sec% (
Set /a out_Sec=%end_Sec%-%start_S
Set remainder=0
)
if %start_Sec% gtr %end_Sec% (
Set /a out_Sec=60-%start_Sec%+%en
Set remainder=1
)
if%end_Min% gtr %start_Min% (
Set /a out_Min=%end_Min%-%start_M
Set remainder=0
)
if %start_Min% gtr %end_Min% (
Set /a out_Min=60-start_Min%+%end
Set remainder=1
)
if%end_Hr% gtr %start_Hr% (
Set /a out_Hr=%end_Hr%-%start_Hr%
)
if %start_Hr% gtr %end_Hr% (
Set /a out_Hr=24-start_Hr%+%end_H
)
echo elapsed time %out_Hr%:%out_Min%:%out_Se
Have a good night and thank u for the help.
Business Accounts
Answer for Membership
by: leewPosted on 2006-04-30 at 15:30:07ID: 16574178
Why don't you just download and use the 2000 resource kit utility, TimeThis.exe - see this: indows2000 /techinfo/ reskit/too ls/ existin g/timethis -o.asp
http://www.microsoft.com/w