| 1. |
Solve : Set Variable Equal to the Second Wednesday of the Month? |
|
Answer» Since the date of the second Wednesday of the month changes every month I am unsure of how to reference this day of the month so I can set it equal to a variable. My plan is to add the logic to a script I run every day to maintain the servers. Instead of manually running a Windows Updates check after Patch Tuesday I want my script to determine if it is the right time in the month to fetch updates. could be diffrent format for you What if they live in (say) Europe? HTTP://ss64.com/nt/date.html Gives a list of date -> locale Also, you may find 'wmic path win32_localtime get day,dayofweek,weekinmonth' to be useful. According to ss64.com it is on XP Pro-win7. Code: [Select]@echo off setlocal EnableDelayedExpansion wmic path win32_localtime get day,dayofweek,weekinmonth for /f "tokens=1,2 delims==" %%A in ('wmic path win32_localtime get day^,dayofweek^,weekinmonth /value') do ( set %%A=%%B ) set dow=%DayOfWeek% set wim=%WeekInMonth% Echo day = %day% echo dow = %dow% echo wim = %wim% :loop.dow if %dow% LSS 3 ( set /a dow+=1 set /a day+=1 ) if %dow% GTR 3 ( set /a dow-=1 set /a day-=1 ) if not %dow% EQU 3 goto :loop.dow :loop.wim if %wim% LSS 2 ( set /a wim+=1 set /a day+=7 ) if %wim% GTR 2 ( set /a wim-=1 set /a day-=7 ) if not %wim% EQU 2 goto :loop.wim echo The second wednesday OCCURS on %day% Sorry for the double post, just realized I had forgotten to clean up my code before posting it. Code: [Select]@echo off setlocal EnableDelayedExpansion for /f "tokens=1,2 delims==" %%A in ('wmic path win32_localtime get day^,dayofweek^,weekinmonth /value') do ( if not "%%A"=="" if not "%%B"=="" set %%A=%%B ) set dow=%DayOfWeek% set wim=%WeekInMonth% :loop.dow if %dow% LSS 3 ( set /a dow+=1 set /a day+=1 ) if %dow% GTR 3 ( set /a dow-=1 set /a day-=1 ) if not %dow% EQU 3 goto :loop.dow :loop.wim if %wim% LSS 2 ( set /a wim+=1 set /a day+=7 ) if %wim% GTR 2 ( set /a wim-=1 set /a day-=7 ) if not %wim% EQU 2 goto :loop.wim echo The second Wednesday occurs on %day%. Thanks guys. As usual I requested help when I needced this right-away but other "hotter" things came up and I haven't gotten a CHANCE to apply your ideas yet. I'll post back for sure when I have. I really appreciate the help. MJ |
|