Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:33:15+00:00 2026-06-18T05:33:15+00:00

I’m using a batch script for the time measurement of commands. I have found

  • 0

I’m using a batch script for the time measurement of commands. I have found this script here on StackOverflow. Unfortunately it sometimes is not working properly and unfortunately I don’t know much about batch programming. I get the impression that it sometimes works and sometimes not. Perhaps I err on this but it does seem that its not working properly after midnight.

The script:

@echo off
setlocal

rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%

rem here begins the command you want to measure
dir /s > nul
rem here ends the command you want to measure

set ENDTIME=%TIME%

echo STARTTIME %STARTTIME%

rem convert STARTTIME and ENDTIME to centiseconds

set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)

echo STARTTIME %STARTTIME%

echo ENDTIME %ENDTIME%

set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)

echo ENDTIME %ENDTIME%

rem calculating the duration is easy
set /A DURATION=%ENDTIME%-%STARTTIME%

rem we might have measured the time inbetween days
if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME%

rem outputing

echo DURATION: %DURATION% in centiseconds

endlocal
goto :EOF

I was using it half an hour ago and I got this result:

STARTTIME  1:29:25.17 
STARTTIME  1:29:25.17 
ENDTIME  1:29:27.82 
ENDTIME  1:29:27.82 
DURATION: 1 in centiseconds

So something with the lines

set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)

and

the line

set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)

seems to be wrong.

What is it?

Regards,
David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:33:17+00:00Added an answer on June 18, 2026 at 5:33 am

    The problem is with "%STARTTIME:~0,2%-100" being " 1", there is an extra space. The program then tries to find the value of (1 1) instead of (101).

    The extra 1 in front should only be for systems that output the time as "01:29:25.17" (to give 101 instead of 01 which the system will interpret as octal number), but for systems that output the time as " 1:29:25.17"(Note the space in front of the 1) there is a problem (which will give 1 1).

    An easy way is just to remove the 1 in STARTTIME=(1%STARTTIME:~0,2%-100)*360000 and ENDTIME=(1%ENDTIME:~0,2%-100)*360000, though that might cause a problem with other systems.

    A more watertight solution would be to add two lines after the rem line:

    rem convert STARTTIME and ENDTIME to centiseconds
    
    set STARTTIME=%STARTTIME: =0%
    
    set ENDTIME=%ENDTIME: =0%
    

    (EDIT: Andriy M’s much shorter method above)


    There are also two set in if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME% which might cause a problem when trying to measure the time between days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.