Can I specify multiple conditions with "or"/"and" in batch file if
block?
If not that complex, can I at least use something like:
if value1 < value < value2
Basically my purpose is to check whether current system time falls in a certain interval(2.05 AM and 7.55 AM to be precise) and if it does, to execute certain commands.
You can break your condition into 2 and use if and if for setting 2 conditions
Adding to dbenham's answer, you can emulate both logical operators (AND, OR) using a combination of
if
andgoto
statements.To test condition1 AND codition2:
To test condition1 OR codition2:
The labels are of course arbitrary, and you can choose their names as long as they are unique.
There are no logic operators in batch. But AND is easy to mimic with two IF statements
Batch IF statements don't know how to compare times. Batch IF knows how to compare integers and strings.
One option is to convert the times into minutes or seconds past midnight.
The other option is to format the time with both hours, minutes (and seconds if needed) to be 2 digits wide each (0 prefixed as needed). The hours should be 24 hour format (military time).