Stack Exchange
Need help in using if condition using windows batch file
Need help in using if condition to set the value of variable in windows batch file
the code I am using  is 
:: This is Code for D3
@echo off
set day=-1
echo >"%temp%\%~n0.vbs" s=DateADD("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& 
right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "filename=%MM%%DD%%YYYY%"
echo "%YYYY%" 
set /a "YYYY-=1"
echo "%YYYY%" 
pause

In the above code I want to modify such that if the month is Jan , Feb and March then the value of YYYY should be YYYY-=1 that is previous year 2017,  else the value should be current year 2018.

Any particular reason why you want to do that in batch rather than VBScript, where it would several orders of magnitude easier?

Any particular reason why you don't use if "%MM%" leq "03"?

this is just a test code, the main code we are using is moving files from one folder to another based on dates. we have created a windows scheduling task to do that. our main objective is to achieve functionality that if file name is like filename=%MM%%DD%%YYYY% then it should move files. we found a bug in the code since company's financial year is from April 1 to March 31

replace set /a "YYYY-=1" with if "%MM%" leq "03" set /a "YYYY-=1", so it will decrease the year only if month is Jan, Feb or Mar.
Note: as you are using YYYY as "current year", you should give the new variable another name, like FYEAR (for "FiscalYear") to avoid confusion). Your code will work fine without that, but if you have a problem with the code next year, you will be glad to have it named with a "speaking name".

Code works. but would you mind please explaining me what is this leq, since I am not a vb programmer , just incase if I want to check if month is greater than march..Thanks

@mb1987, leq is batch-file operator syntax for less than or equal. At a CMD prompt, type if /? for information about these operators.
