I need to create a program that takes the current date and if that date is between the 10th and the 20th of the month, print the date of the last month in YYYYMM format (that is, month -1).
The code I made is the following:
@echo off &setlocal
setlocal EnableDelayedExpansion
SET _test=%date%
SET _month=%_test:~4,2%
SET year=%_test:~10,4%
SET day=%_test:~7,2%
if %day% GTR 10 (
if %day% LSS 20 (
IF %_month% EQU 1 (
set search_month=12
set /a search_year= %year% -1
)
IF %_month% EQU 2 (
set search_month=01
set /a search_year= %year%
)
IF %_month% EQU 3 (
set search_month=02
set /a search_year= %year%
)
IF %_month% EQU 4 (
set search_month=03
set /a search_year= %year%
)
IF %_month% EQU 5 (
set search_month=04
set /a search_year= %year%
)
IF %_month% EQU 6 (
set search_month=05
set /a search_year= %year%
)
IF %_month% EQU 7 (
set search_month=06
set /a search_year= %year%
)
IF %_month% EQU 8 (
set search_month=07
set /a search_year= %year%
)
IF %_month% EQU 9 (
set search_month=08
set /a search_year= %year%
)
IF %_month% EQU 10 (
set search_month=09
set /a search_year= %year%
)
IF %_month% EQU 11 (
set search_month=10
set /a search_year= %year%
)
IF %_month% EQU 12 (
set search_month=11
set /a search_year= %year%
)
set /a tosearch = %search_year%%search_month%01
echo tosearch is %tosearch%
set /a actualdate = %year%%_month%01
echo actualdate is %actualdate%
)
)
The drawback I have is that, after executing this program, both variables (currentdate and tosearch) are empty. What is the error in the code?