Search code examples
batch-filegoto

only do if day... batch file


hello i got a batch file, something like this:

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

Now i know the first line won't work.

What i actually want to happen:

It automatticly checks which day it is. If it is Monday to Friday, it has to go to 'yes', otherwise (saturday/sunday) to 'no'.

How to do this?


Solution

  • I ran across this online. Tested, and it works. Returns the day as an integer, which you can still work with.

    @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( 
        Set Month=%%A
        Set Day=%%B
        Set Year=%%C
    )
    
    @echo DAY = %Day%
    @echo Month = %Month%
    @echo Year = %Year%