@echo off setlocal enabledelayedexpansion :: *** Get the current date into the variables dd, mm, yy: set day = %date% echo %date% for /f "tokens=1-3 delims=/" %%a in ("%date%") do ( set dd=%%a set mm=%%b set yy=%%c ) set Feb=28 set /a Leap=yy %% 4 if "%Leap%"=="0" set Feb=29 set i=101 for %%a in (31 %Feb% 31 30 31 30 31 31 ott34 31 35 31) do ( set /a i+=1 if !i!==1%mm% set LastDay=%%a ) echo This month's last Day: [%LastDay%] if %dd%==%LastDay% echo Today is the last day of this month. echo ***** start business day script ***** echo 0=Sunday - 1=Monday - 2=Tuesday - 3=Wednesday - 4=Thursday - 5=Friday - 6=Saturday for /f %%x in ('wmic path win32_localtime get /format:list ^| findstr "="') do set %%x set day=%DayOfWeek% echo ***** number day: %DayOfWeek% ***** set result=false IF "%day%"=="6" set result=true IF "%day%"=="0" set result=true IF "%result%" == "true" ( ECHO ***** is not a business day ***** ) ELSE ( ECHO ***** business day %LastDay% ***** ) REM if %dd%==%LastDay% call fri.bat pause
@echo off setlocal rem Get current date and time into LocalTime. environment variables (see comments in subroutine) call :GetLocalTime N rem Calculate days in the current month call :DaysInMonth %LocalTime.Year% %LocalTime.Month% rem Determine if this is the last workday of the month call :IsLastWorkDay rem ===== JUST FOR TESTING TO SHOW SOME OF THE VARIABLES INVOLVED ===== echo Year: %LocalTime.Year% echo Month: %LocalTime.Month% echo Day: %LocalTime.Day% echo DayOfWeek: %LocalTime.DayOfWeek% echo DaysInMonth: %DaysInMonth% echo IsLastWorkDay: %IsLastWorkDay% rem If last work day of month do desired processing if "%IsLastWorkDay%" EQU "Y" ( rem ===== TO BE ADDED, PERFORM WHATEVER LOGIC YOU WANT ON THE LAST WORKDAY ===== rem call fri.bat ) rem Find out what the first work day was for this month call :FirstWorkDay %LocalTime.Month% %LocalTime.Year% echo FirstWorkDay: %LocalTime.Month%/%FirstWorkDay%/%LocalTime.Year% rem End main script exit /b rem Get current date and time via WMIC, return in variables (see below) :GetLocalTime [zero-pad(Y/N)] rem Sets these variables for further reference ("*" items will be zero filled if requested) rem LocalTime.Year rem LocalTime.Month (*) rem LocalTime.Day (*) rem LocalTime.Hour (*) rem LocalTime.Minute (*) rem LocalTime.Second (*) rem LocalTime.DayOfWeek (0 to 6, where 0=Sunday) rem LocalTime.WeekInMonth rem LocalTime.Quarter rem Execute WMIC command to get date time elements for /f "tokens=*" %%A in ('wmic /output:stdout Path Win32_LocalTime Get * /Format:value^|find "="') do ( rem pass output through another FOR to remove trailing carraige returns for /f "tokens=*" %%B in ("%%A") do ( rem set values into variables prefaced by "LocalTime." set "LocalTime.%%B" ) ) rem If requested, left pad with zero common 2 digit values if /i "%~1" EQU "Y" ( for %%a in (LocalTime.Month LocalTime.Day LocalTime.Hour LocalTime.Minute LocalTime.Second) do ( if !%%a! LSS 10 set %%a=0!%%a! ) ) rem Return to caller exit /b rem Subroutine to calculate days in current month, handling leap years :DaysInMonth Year Month setlocal DisableDelayedExpansion set /a "yy = %~1, mm = %~2" set /a "n = 30 + !(((mm & 9) + 6) %% 7) + !(mm ^ 2) * (!(yy %% 4) - !(yy %% 100) + !(yy %% 400) - 2)" endlocal & set DaysInMonth=%n% exit /b rem Subroutine to determine if this is last work day of month :IsLastWorkDay setlocal EnableDelayedExpansion rem Assume it isn't for now set Result=N rem If today is the last day of the month, and not a weekend day, then it is last workday if %LocalTime.Day% EQU %DaysInMonth% ( if %LocalTime.DayOfWeek% NEQ 0 ( if %LocalTime.DayOfWeek% NEQ 6 ( set Result=Y ) ) ) else ( rem Not last day of month, see if its a friday, and if the month ends over the weekend if %LocalTime.DayOfWeek% EQU 5 ( set /a "DaysToEndOfMonth = DaysInMonth - LocalTime.Day" if !DaysToEndOfMonth! LEQ 2 set Result=Y ) ) rem Return result to caller in environment variable endlocal & set IsLastWorkDay=%Result% exit /b rem Subroutine to determine first work day of a month :FirstWorkDay [Month] [Year] setlocal EnableDelayedExpansion rem Check from day 1 to 7 to find first day that is not a weekend day for /l %%A in (1,1,7) do ( call :DayOfWeek %~1 %%A %~2 if !DayOfWeek! NEQ 6 ( if !DayOfWeek! NEQ 0 ( endlocal & set FirstWorkDay=%%A exit /b ) ) ) rem Should never get here, return -1 just in case endlocal & set FirstWorkDay=-1 exit /b rem Calculate the day of week number (0=Sunday) for a specific date :DayOfWeek [Month] [Day] [Year] setlocal set /a a=(14-%1)/12 set /a y=%3-%a% set /a m=%1+12*%a%-2 set /a dow=(%2+%y%+%y%/4-%y%/100+%y%/400+(31*%m%)/12)%%7 endlocal & set DayOfWeek=%dow% exit /b
So if the script ran on July 29, 2016 you want the file to copy, but not on July 30, 2016 or July 31, 2016?