I have created a batch file that regularly gets triggered from an automated job.
Within the batch file, I want to check if time is between 12AM and 8AM, set a variable with a particular value, otherwise, set it to the default.
Any tips I how might do this in a batch file?
Edit – zb226 is correct – the above is more complicated than need be. Much simpler to do
The leading 0 in 08 is critical. The reason is that numbers preceded by 0 are treated as octal notation, and 8 and 9 are not valid octal digits. The IF statement will do a string comparison if it sees an invalid octal number on either side. So if the current hour is 09, then
09 lss 8is TRUE because 0 sorts before 8. Changing to09 lss 08gives the correct answer.Either solution above sets the value to default if it is exactly 8:00:00.00 AM. If you really want the “particular value” through 8:00:00.00 AM and default any time after, then it is a bit more complex. In that case I would revert back to the FOR solution.