time calculation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
eamjam
Posts: 1
Joined: 31 Mar 2010 20:40

time calculation

#1 Post by eamjam » 31 Mar 2010 20:47

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

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: time calculation

#2 Post by jeb » 01 Apr 2010 13:06

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

Post Reply