I am building a process that requires me to extract the year from a file name.
The file name is as follows:
The year will always be the last string preceeding the .csv.hp_profitandloss_extract_FY08.csv
I need to extract the year and set it in a variable and also set another variable that is 1 less. I run into an issue with batch subtraction when there is a leading zero. Is there an eays way around this?
This is what I have and works fine, except when encountrring a leading zero:
Thanks!
SET "DATAFILENAME=%~1"
SET "ENDYEAR=%DATAFILENAME:~-6%"
SET "ENDYEAR=%ENDYEAR:~0,2%"
SET /A "STARTYEAR=%ENDYEAR%-1"
SET "STARTPOV=Sep-%STARTYEAR%" & SET "ENDPOV=Oct-%ENDYEAR%"
echo %STARTYEAR%
echo %ENDYEAR%
pause