One case when the script gives incorrect values is at the end of the month (when the script starts this month but ends in the next month).
I will use this script in one of my next post when I will do a compression benchmark with 7-zip. It will calculate the time taken to compress a file.
So, here's the script:
@echo off
::::::::::::::::::::::::::::::::::::::::::
:: TimeDiff v1.00 by LEVENTE ROG ::
:: www.thesysadminhimself.com ::
::::::::::::::::::::::::::::::::::::::::::
::[ EULA ]:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Feel free to use this script. The code can be redistributed ::
:: and edited, but please keep the credits. ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::[ CHANGELOG ]::::::::::::::
:: v1.00 - First Version ::
:::::::::::::::::::::::::::::
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Second /Format:table ^| findstr /r "."') DO (
set Milisecond=%time:~9,2%
set Day=%%A
set Hour=%%B
set Minute=%%C
set Second=%%D
)
set /a Start=%Day%*8640000+%Hour%*360000+%Minute%*6000+%Second%*100+%Milisecond%
::
::
:: PUT COMMANDS HERE
ping www.thesysadminhimself.com
::
::
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Second /Format:table ^| findstr /r "."') DO (
set Day=%%A
set Hour=%%B
set Minute=%%C
set Second=%%D
)
set Milisecond=%time:~9,2%
set /a End=%Day%*8640000+%Hour%*360000+%Minute%*6000+%Second%*100+%Milisecond%
set /a Diff=%End%-%Start%
set /a DiffMS=%Diff%%%100
set /a Diff=(%Diff%-%DiffMS%)/100
set /a DiffSec=%Diff%%%60
set /a Diff=(%Diff%-%Diff%%%60)/60
set /a DiffMin=%Diff%%%60
set /a Diff=(%Diff%-%Diff%%%60)/60
set /a DiffHrs=%Diff%
:: format with leading zeroes
if %DiffMS% LSS 10 set DiffMS=0%DiffMS!%
if %DiffSec% LSS 10 set DiffMS=0%DiffSec%
if %DiffMin% LSS 10 set DiffMS=0%DiffMin%
if %DiffHrs% LSS 10 set DiffMS=0%DiffHrs%
echo %DiffHrs%:%DiffMin%:%DiffSec%.%DiffMS%
NOTE: To copy the entire code, just double-click and hit CTRL+C
It's quite nice, but the milliseconds are not calculated.
ReplyDelete... and it's less nice now since it doesn't calculate task over an hour long properly it seems.
ReplyDelete:: format with leading zeroes
ReplyDeleteif %DiffMS% LSS 10 set DiffMS=0%DiffMS!%
if %DiffSec% LSS 10 set DiffMS=0%DiffSec%
if %DiffMin% LSS 10 set DiffMS=0%DiffMin%
if %DiffHrs% LSS 10 set DiffMS=0%DiffHrs%
Is OBVIOUS wrong instead it must be:
:: format with leading zeroes
if %DiffMS% LSS 10 set DiffMS=0%DiffMS!%
if %DiffSec% LSS 10 set DiffSec=0%DiffSec%
if %DiffMin% LSS 10 set DiffMin=0%DiffMin%
if %DiffHrs% LSS 10 set DiffHrs=0%DiffHrs%
That SHOULD declare the two other comments ;)
But thank you for the rest of the code...
good script to calculate time
ReplyDelete