0

Neither

@echo off

set hh=!tm:~0,2
set mm=!tm:~3,2
set ss=!tm:~5,2
set ms=!tm:~7,2

if !hh! gtr **5** (
    echo gtr 5
    pause
    goto success
)


pause
goto fail

:success
echo Success!
pause
exit

:fail
echo Fail!
pause
exit

or

@echo off

set hh=!tm:~0,2
set mm=!tm:~3,2
set ss=!tm:~5,2
set ms=!tm:~7,2

if !hh! gtr **05** (
    echo gtr 5
    pause
    goto success
)


pause
goto fail

:success
echo Success!
pause
exit

:fail
echo Fail!
pause
exit

works as i need it to

This should get it to output that it is greater than 5 am when it is 10 am. It only states it is less than 5 am even though it is 10 am. On top of that if I set the hour to 5 am it still says it is less than 5 am and not equal to 5 am.

It only does this for anytime that is a single digit, so 0-9 (which is 12am to 9 am). Any time that is a double digit, so 10-23 (which is 10am to 11pm), works and says the correct things.

Troy Rash
  • 29
  • 4

2 Answers2

2

try this:

@ECHO OFF &SETLOCAL
set /a HH=0
FOR /f "tokens=1*delims=0" %%a IN ("$0%time:~0,2%") DO SET /a HH=%%b 2>nul
IF %HH% GTR 5 ECHO Alert!
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • Works great for hours and minutes, but doesn't seem to want to work for location ~5,2 for seconds. – Troy Rash Jul 10 '13 at 21:27
  • I have the seconds at `:~6,2` (check it out: `23:32:39,70`) – Endoro Jul 10 '13 at 21:33
  • i ran it at the ~6,2 it seems to pick and choose wen it want to stop or not. It is really picky on the 0's where it just flys by and and says missing operation. – Troy Rash Jul 10 '13 at 21:38
  • What is the output of `echo %time%` ? – Endoro Jul 10 '13 at 21:43
  • I find it only does when going through anytime that is 0 seconds. Even if i'm not trying to stop it at 0 seconds. Also now it seems to being more constant for trying to make it stop at 15s, but stopping 1ms early which isn't bad. Code: `@ECHO OFF :time echo %time% FOR /f "tokens=1*delims=0" %%a IN ("$0%time:~6,2%") DO SET /a SS=%%b IF %SS% equ 15 goto success goto time :success echo success finally pause goto time` – Troy Rash Jul 10 '13 at 21:47
  • also i read the fast paced dissapearing wrong it actually says `14:55:00.95 Missing operand. 14:55:00.95 Missing operand. 14:55:00.95 Missing operand.` – Troy Rash Jul 10 '13 at 21:57
  • So put `2>nul` at the end. – Endoro Jul 10 '13 at 22:00
  • This seems to be causing a missing operand for hours,minutes, or seconds being set to 0. If you can help on the 0 problem, please refer to [Link](http://stackoverflow.com/questions/17621363/batch-during-my-code-loop-it-stops-setting-a-variable-all-help-welcome) – Troy Rash Jul 12 '13 at 21:22
2
@ECHO OFF
SETLOCAL
SET testvalues=" 1" " 4" " 5" " 6" "10" "12" "13" "19" "20" "23" "01" "04" "05" "06" "08" " 0" 
FOR %%i IN (%testvalues%) DO CALL :test2 %%i
echo==================================
FOR %%i IN (%testvalues%) DO CALL :test %%i
GOTO :eof
:test
SET value=%~1
SET "HH="
FOR /f "delims=0" %%a IN ("%value:~0,2%") DO SET /a HH=%%a
IF %HH% GTR 5 (ECHO Alert! FOR %1 ) ELSE (ECHO Silent FOR %1 )

GOTO :EOF
:test2
SET value=%~1
SET "HH="

SET /a HH=1%value: =0%
IF %HH% GTR 105 (ECHO Alert! FOR %1 ) ELSE (ECHO Silent FOR %1 )

GOTO :EOF

Results:

Silent FOR " 1" 
Silent FOR " 4" 
Silent FOR " 5" 
Alert! FOR " 6" 
Alert! FOR "10" 
Alert! FOR "12" 
Alert! FOR "13" 
Alert! FOR "19" 
Alert! FOR "20" 
Alert! FOR "23" 
Silent FOR "01" 
Silent FOR "04" 
Silent FOR "05" 
Alert! FOR "06" 
Alert! FOR "08" 
Silent FOR " 0" 
=================================
Silent FOR " 1" 
Silent FOR " 4" 
Silent FOR " 5" 
Alert! FOR " 6" 
Silent FOR "10" 
Alert! FOR "12" 
Alert! FOR "13" 
Alert! FOR "19" 
Silent FOR "20" 
Alert! FOR "23" 
Silent FOR "01" 
Silent FOR "04" 
Silent FOR "05" 
Alert! FOR "06" 
Alert! FOR "08" 
Missing operand.
5 was unexpected at this time.

Note : corrected behaviour for hours=10, 20 and 0

Magoo
  • 77,302
  • 8
  • 62
  • 84