Page 1 of 1

time calculation

Posted: 31 Mar 2010 20:47
by eamjam
I am just wondering how to deduct time that said I have to record a time and after some task I need to record time again...I can do upto that but now I need to find out the time difference....that is for the time needed to do that some task...any help hint would be appreciated

Re: time calculation

Posted: 01 Apr 2010 13:06
by jeb
Hi eamjam,

use the %time% and calculate the seconds since 0:00.

Sample.

Code: Select all

call :timeToMs ms_start "%start%"
call :timeToMs ms_end "%end%"

echo %start%=%ms_start%ms
echo %end%=%ms_end%ms
set /a diff_ms=ms_end-ms_start
echo diff=%diff_ms%ms
goto:eof


::::::::::::::::::.
:timeToMs <resultVar> <time>
::: convert a time (in normal 24h representation of the civilized world) to milli seconds from 0:00
SETLOCAL
FOR /F "tokens=1,2,3,4 delims=:,.^ " %%a IN ("%~2") DO (
  set /a ms=^(^(^(30%%a%%100^)*60+7%%b^)*60+3%%c-42300^)*1000+^(1%%d0 %% 1000^)
)
(
  ENDLOCAL
  set %~1=%ms%
)



jeb