Revin Ray
Revin Ray

Reputation: 1

check time in bat file and continue with action?

I'm trying to run another bat file using this one at a certain time but whenever I try, it runs it no matter what.

@echo off
setlocal enableextensions enabledelayedexpansion

ping www.google.com

pause

start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://inbox.google.com"

set tm=time

set hh=!tm:~0,2!
set mm=!tm:~3,2!
if !hh! lss 19 (
    goto :done
)
if !hh! equ 19 (
    if !mm! lss 45 (
        goto :done
    )
)
start "" "C:\Users\AdminNUS\Desktop\Dimmer.bat"
:done
endlocal

Upvotes: 0

Views: 82

Answers (1)

MichaelS
MichaelS

Reputation: 6032

The error is here: set tm=time This line stores the string time in the variable %tm%. So set hh=!tm:~0,2! stores ti in %hh% and so on. To fix this you simply have to surround time with %%:

set tm=%time%

This should be it.

Upvotes: 1

Related Questions