mardi 18 mai 2021

cmd batch file check if current hour is equal to one of specific hour

I would like to develop a batch file to check the current time hour is equal to specific hour.

As long as n+2 hour (e.g. 0, 2, 4, 6, 8, 10, etc...) is matched with system current hour, it will echo to valid message, otherwise it will echo to invalid message.

Anyone can help me? Thanks.

Source Code

FOR /F %%a IN ('Powershell -Nop -c "Get-Date -Format 'HH'"') DO SET getcurrHour=%%a
FOR /L %%a IN (0,2,22) DO SET hourList=%%a
    
IF %getcurrHour% == %hourList% (
    
    ECHO It's valid.
    
) ELSE (
    
    ECHO It's not valid.
)

Aucun commentaire:

Enregistrer un commentaire