DOS TIME command

I'm currently attempting to write a batch file in DOS that will open a program when the interal clock hits a certain time.

This is what I have so far:

ECHO It's now %TIME%
IF %TIME%=="10:33:00.00a" START c:/myprog.exe GOTO END


If you're familiar with the TIME command, you know what my problem is. The loop is working perfectly and comparing the time to the string I specify, but the time it takes to execute the loop is not a perfect second. The clock never reaches 10:30:00.00a, but it does hit 10:30:00.01a, 10:30:01.03a, etc. Presumably, if I ran this batch file at precisely the right time, the interal clock would hit 00.00 and the program would spawn, but that's impossible to count on.

I'm new to batch file programming, and I know what I need to do is extract the hour and minute parts of the time command and compare them, but I'm at a loss as how to do this. Previously, I attempted to use wildcard characters in my compare string for the second arguments, but that did not work either.

Can anyone help?
Who is Participating?
KangaRooConnect With a Mentor Commented:
@echo off
   VER | TIME | FIND "15:02"
   if errorlevel 2 goto error
   if errorlevel 1 goto loop
   echo Its time!
   goto endit
  echo An error occurred!
All else aside, there are a couple of bugs on your comparison line:

IF %TIME%=="10:33:00.00a" START c:/myprog.exe GOTO END

Firstly, you have to start "c:\myprog.exe" - you used the wrong kind of slash.

Secondly, since %TIME% doesn't contain quotes itself, you have to either remove the quotes around the comparison time, or write "%TIME%"=="10:33:00.00a"

However, neither of these will actually solve your problem (unless you're lucky).  The main problem is that you're seeing the hundredths of a second; and you can't mask these off in straight DOS.

There are a number of ways to solve this, the easiest probably to write a program that returns the current time without the hundredths.  In this case you would have to be careful that the program is only called once; in your code above it's possible for it to be called more than once in succession.

If you have Windows 95 (with Plus), Windows 98 or later, you should use the System Agent/Task Scheduler instead - it's more reliable.
punkerAuthor Commented:
Thank you for pointing out the many bugs in my code. As I'm new to DOS batch files, that's to be expected.

Yes, I know my problem lies in the seconds and hundredths of a second being returned by the time command. My hope is that someone will know of a way to extract the hour and minute from the time command so I may compare them.

If anyone knows how to do this via DOS batch file programming, please respond.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

As I said, you cannot do it purely in DOS; you need help from a real programming language such as C or BASIC.

To help you out, I wrote a little program that will let you get the time without the hundredths, or without the seconds, or whatever.
Get it at

There's a text file in there which explains how to use the program.

And don't forget to modify your code to avoid multiple executions, especially if you ignore the seconds.
punkerAuthor Commented:
There MUST be a way to do this in DOS. I can't accept being told an operating system simply can't do something, especially when I'm quite sure it can be done.
I need to do this all in DOS. C or BASIC are out of the question.
The multiple executions are there so the batch file can be run at any time and will continue executing until the specified time, and will then open the program in question. So I can't see how to avoid that.
I haven't downloaded your zip file, partially because I'm not sure what's in it, but mostly because I'm very wary of downloading anything from the internet. If what is in the zip file is an all DOS solution, could you possibly post the code instead of hyperlinking to a download site?

I'm rejecting because I'd like to keep this open to all until I find an answer I can live with. Since I can accept comments as answers, there isn't any reason to lock the question.
Take a look at FIND. You could use something like
VER |  TIME | FIND "15:02"
if errorlevel

FIND will set errorlevel depending on result. I've forgotten the exact values but you can easily test.
Another option is to write a small programm to check the current time. It could do several things:
- set the errorlevel if current time is within certain criteria.
- wait until the specified time.
And of course, execute a specified program at a pre-determined time (a kind of scheduler)
punkerAuthor Commented:
Brilliant! I knew it was something really simple I wasn't catching.

Thanks a lot!

Yeah, writing batches often involves serious abuse of all kinds of tools and commands ;) Can be real fun though :-))
You're welcome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.