I want to create a batch to check if the file have been modified to today's date, what i did was to "bring in a system's date and compare it with the modified date, if they match, then trigger something. My batch file works well and displays two right dates, but the IF statement saying the date mismatch.
@ECHO OFF
for /f "tokens=1,2,3,4 delims=. " %%i in ('date /t') do set date=%%k%%j
echo %date%
pause
FOR %%a IN (D:\MyFile.txt) DO SET FileDate=%%~ta
set DATEONLY=%FileDate:~0,10%
echo %DATEONLY%
pause
if DATEONLY==date (
echo date ok
)
else (
cls
ECHO Wrong
)
PAUSE
There are the following problems:
dateas this is a built-in variable containing the current date (typeset /?for help);forstatement is useless, because%date%is already available;DATEONLYanddateare compared literally in yourifstatement, you need to state%DATEONLY%==%date%instead;elsestatement must be in the same line as the closing parenthesis of theifbody (typeif /?for help);So try this:
Note: Regard that all those dates in the batch file are locale-dependent.