The date environment variable reference %date%
is replaced by Windows command interpreter during the preprocessing state by the region (country) dependent string before the IF command is executed at all.
On running the batch file from within a command prompt window it can be seen that the IF command line is after preprocessing:
if Sun 10/15/2017=="Sun 10/15/2017" ( echo "Today is Sunday" ) else ( echo "Today is Unknown" )
So the syntax of IF command is not correct after environment variable expansion because there is Sun
as first argument, a space and Sun 10/15/2017=="Sun 10/15/2017"
being interpreted as unexpected operator.
Whenever comparing strings it is recommended to use double quotes as only within a double quoted string the space character is not interpreted as argument separator. And the characters &()[]{}^=;!'+,`~|<>
are also interpreted as literal characters within a double quoted string.
The double quotes are also compared by IF on running the string comparison. So it is needed that both compared strings are enclosed in double quotes.
@echo off
if "%DATE%"=="Sun 10/15/2017" ( echo "Today is Sunday." ) else ( echo "Today is unknown." )
pause
Another solution if region dependent date really contains the abbreviated weekday too.
@echo off
if not "%DATE:Sun=%"=="%DATE%" ( echo "Today is Sunday." ) else ( echo "Today is unknown." )
pause
This batch file compares the current date string with all case-insensitive occurrences of Sun
being replaced by nothing with unmodified current date string. The string substitution is successful only on date string containing weekday abbreviation Sun
and in this case the two compared strings are not equal.
On my computer the IF condition is never true as %DATE%
expands to a date string not containing weekday according to configuration in Windows Region and Language settings.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.