简体   繁体   中英

Batch Variable Range for %TIME%

For school, I would like to be able to create a batch file that will check what the %TIME% variable is and if it 8:15-9:45 , then goto my first period folder 9:45-10:30 to goto second period, etc. I know how to do this if there is a specific time, but not how to set a range of time. Any help would be greatly appreciated! Thanks.

One way is to convert the time into HHMMSS format. Something like this

set timep=%time%
if "%timep:~1,1%" == ":" set timep=0%timep%
set timeval=%timep:~0,2%%timep:~3,2%%timep:~5,2%

Now set the default period to 0

set /a period=0

Since in string form 083000 is between 081500 and 094500, you can just stick to string comparisons without converting to numeric

...
if /i %timeval% geq 103000 set /a period=%period%+1
if /i %timeval% geq 094500 set /a period=%period%+1
if /i %timeval% geq 081500 set /a period=%period%+1

%period% will now hold 0 if the time is less than 0815, 1 if it is between 0815 and 0945 etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM