time variable batch file

April 15, 2011 at 00:56:14
Specs: Windows XP
I am working a batch file that copy files from c: to d: and I need the total time taken. I add this line " echo %date% %time%" but only get the current time. what I need is (start time - end time) . Please give guidence. Thanks

See More: time variable batch file

Report •

April 15, 2011 at 01:58:04
Should be (end time - start time).

Here's a script I produced a long time ago. Not fully tested but might be of some help to you.

@echo off
setlocal enabledelayedexpansion

set vbs=%temp%\vbs.vbs
echo wscript.echo timer>%vbs%

set evaluate=%temp%\evaluate.vbs
echo wscript.echo eval(wscript.arguments(0))>%evaluate%

call :getsecs startsecs

<your commands go here...>


call :getsecs stopsecs

set c=CCur(!stopsecs!)-CCur(!startsecs!)
call :calc1 elsecs

call :calc2 %startsecs% starthour startmins startsecs startmsec 

echo  StopSecs=!stopsecs!
echo StartSecs=!startsecs!
echo ElapsedSecs=!elsecs!


for /f "tokens=*" %%1 in ('cscript //nologo %vbs%') do (
    set secs=%%1
endlocal&set %1=%secs%&goto :eof

for /f %%1 in ('cscript //nologo %evaluate% "%c%"') do (
    set result=%%1
endlocal&set %1=%result%&goto :eof

for /f "tokens=1-2 delims=." %%1 in ("%1") do (
    set totsecs=%%1& set msecs=.%%2

for /f "tokens=1-2 delims=." %%1 in ("%startsecs%") do (
    set startsecs=%%1& set msecs=%%2
set /a hour=%startsecs%/3600
set /a mins=(%startsecs%-(%hour%*3600))/60
set /a secs=%startsecs%-(%hour%*3600)-(%mins%*60)

echo %hour%.%mins%.%secs%.%msecs%

If you have Admin privileges you could download/install a command line utility which will do the job for you, such as Ptime from http://www.pc-tools.net/win32/ptime/

Good luck.

Report •

April 15, 2011 at 02:39:50
Alternatively, there's VBScript, which can copy files, can do DateTime math, and is native to Windows.

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question