how to code in dos 'if current time GEQ (=)

September 14, 2010 at 06:39:52
Specs: Windows XP
i want to code in a dos script

if current time >= 07:00 do something


See More: how to code in dos if current time GEQ (=)

Report •


#1
September 14, 2010 at 07:24:57
This will be very hard becaus Cmd thinks the last 2 numbers are a trigger

Report •

#2
September 14, 2010 at 12:01:14
I'm thinking I'm missing something in the time logic here... but as far as I can think it at this point I'd assume this should work... (changing HH:MM to be your 24hr format time)


for /f "delims=: tokens=1,2" %%a in ("%time%") do set stime=%%a:%%b
if %stime% GEQ HH:MM echo Success


Report •

#3
September 14, 2010 at 22:55:53
Be warned: CMD will do a text comparison, so 2:01 AM will be > 12:01 PM.

If you must do date/time math, pick a language that supports it, like VBScript or JScript.


Report •

Related Solutions

#4
September 15, 2010 at 16:12:40
What if we change to:

for /f "delims=: tokens=1,2" %%a in ("%time%") do set stime=%%a%%b
if %stime% GEQ HHMM echo Success

I assume that removing the colon from the two numbers should make it a straight number compare vs. a text compare (though I am also operating under the assumption that %time% always returns the time in 24hr format)?


Report •


Ask Question