only do if day… batch file

后端 未结 7 1737
南笙
南笙 2021-02-09 00:43

hello i got a batch file, something like this:

if %day%==monday, tuesday, wednesday, thursday, friday (
goto yes
) else (
goto no
)

Now i know

7条回答
  •  渐次进展
    2021-02-09 01:18

    From this answer, we have

    wmic path win32_localtime get dayofweek
    

    Expanding on this based on suggestions in this thread, we can set a dayofweek variable as follows:

    @echo off
    REM Unset dayofweek in case set in a previous execution of this batch file
    set dayofweek=
    REM Get dayofweek into a variable.  Locale-specific:  0 is either Sunday or Monday.
    for /F "skip=1 tokens=*" %%a in ('wmic path win32_localtime get dayofweek') do if not defined dayofweek set dayofweek=%%a
    echo %dayofweek%
    

    Note that 0 can be Sunday or Monday depending your locale.

提交回复
热议问题