Why won't this batch script work?

I am making an alarm/timer script, and this line isn't working.:

IF '%TIME%'=='0:18:05.20' (GOTO yes) ELSE (GOTO LOOP)

It works when I put %DATE% in instead like this:

IF '%DATE%'=='03/01/2011' (GOTO yes) ELSE (GOTO LOOP)

It quits really quickly with the first line, but i was able to see what is says, and it says

0:18:05.20 was unexpected at this time.

What's going wrong?

sort by: active | newest | oldest
Your batch file will most likely work after 12... if you use double quotes it should be fine... for some reason when you have times returning a space first like " 0:18:05.20" it will cause the error above when using single quotes... so below will work...

IF "%TIME%"==" 0:18:05.20" (GOTO yes) ELSE (GOTO LOOP)
echo Time is an illusion
XOIIO (author)  rocketsurgery6 years ago
BRILLIANT! It works like a charm! Now I can have an alarm on my pc for hwen I am working on stuff! THANK YOU SO MUCH!

(BTW, love the time is an illusion part)
I have created a similar script myself, but mine did not have to be constantly running in a shell the entire time. Instead, it uses svchost to schedule task.

What I did, was use the "AT" command, which you can use to schedule a task (such as another batch script) to run at a certain time, day, and how often to run it.

However, Administrator privileges are required to use the "AT" command.

For syntax, just type "AT /?" in a console.
lemonie6 years ago

Can you use a greater than function? and what does that do?

XOIIO (author) 6 years ago
That might help, but for some reason it shows something like this.

01:12:56.45’ ’==‘00:18:05.20’ was not expected at this time.

When I put it in like this

IF 'TIME'=='02:57:00.00' (GOTO yes) ELSE (GOTO LOOP)

is stays open and echoes waiting --part of the script-- but when the time changed it didn't help.