The IF command matches all characters, including the quotes - Thu
does not match "Thu"
.
So either of the following will work:
if %RDAY%==Thu ...
if "%RDAY%=="Thu" ...
EDIT - I just realized you added quotes to the value when you defined RDAY. So my suggestion above in yellow is not quite correct. I prefer to use set "RDAY=%date:~0,3%"
, which does not add quotes to the value. But that is more a matter of style.
So presumably your IF statement is never true because your machine uses a different format for the %DATE%
value that does not start with the day-of- week abbreviation
But there are other problems with your script:
Only your log line is conditional, the Thursday script will run everyday. This is easily fixed by adding parentheses to your IF block
if %DATE:~0,3%==Thu (
echo "Starting Weekly Matching" >> %LOGFILE%
D:\New_Folder\SCRIPTTEST\Runthursday.bat
)
The format of the %DATE%
value is locale dependent. Your script will likely not work on another machine. You can use WMIC to easily determine if it is Thursday in a locale agnostic way:
wmic path win32_localtime get dayofweek | findstr 4 >nul && (
echo "Starting Weekly Matching" >> %LOGFILE%
D:\New_Folder\SCRIPTTEST\Runthursday.bat
)
But I have a question for you - Why are you scheduling a daily batch job that runs another batch only on Thursday? If you want to run a batch job on Thursdays, then use the Windows Task Scheduler to do just that. There is no need to determine if today is Thursday in your batch script, let the scheduler do the work.