only do if day… batch file

后端 未结 7 1731
南笙
南笙 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:12

    As Jay has mentioned, using date /t will only work on locales where this command outputs the day of week along with the date, and won't work on other locales (e.g. Russian). If you don't mind mixing your batch files with some VBScript, here's a solution that should work on all locales.

    The trick is this tiny VBScript script that outputs the day of the week as a number (1 = Sunday, 2 = Monday, ... 7 = Saturday):

    WScript.Echo DatePart("w", Date)
    

    You can run this script from your batch file, read its output and apply your logic:

    for /f %%d in ('cscript dayofweek.vbs //nologo') do (
      if %%d==7 goto no   :: Saturday
      if %%d==1 goto no   :: Sunday
    )
    goto yes
    

提交回复
热议问题