Skip navigation

JSI Tip 1986. How can I get an accurate time in a batch job?

In a batch job, when you issue a

time /t

Windows NT returns hh:mm, as in 16:47.

If you type


at a command prompt, windows NT returns hh:mm:ss.hs, as in 16:47:03.20, but prompts for a new time.

If you need the more accurate time in a batch job, and your command processor isn't broken, use the following:

for /f "tokens=5-8 delims=:. " %%a in ('echo.^|time') do set thh=%%a&set tmm=%%b&set tss=%%c&set ths=%%d
You can then do whatever calculation required, using the set /a syntax, as in Time Math.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.