Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 763
Deniz Zoeteman Avatar asked Jun 01 '09 17:06

Deniz Zoeteman


1 Answers

Here is an example bat file that will do this sort of thing I am sure you can think of other ways to use this sample code. For instance anytime you need an "in" list. The tricky bit is the %date:~0,3% this says expand the %date% environment variable and starting at position 0 the beginning of the string return the next 3 characters. You can learn more about this from the "set /?" command.

example: IsWeekDay.bat

@echo off
setlocal

for %%i in (Mon,Tue,Wed,Thu,Fri) do (
    if "%date:~0,3%"=="%%i" goto YES
)

:NO
echo No
goto EOF

:YES
echo Yes

:EOF
endlocal
like image 141
Jeremy E Avatar answered Nov 10 '22 00:11

Jeremy E