I have some batch files that currently run every day that basically open system files as soon as the system data is updated in the morning (which can be at different times depending on the day).
The current batch files (created from CMD) all run a simple start:... command to open the files.
I am looking for a way to only run some of the batch files on Mondays and Thursdays, but not open the programs on any other day. Basically if the batch file runs every day, it would do nothing unless it was Monday or Thursday, and then it would open the system file.
You could find the day of the week using
wmic path win32_localtime get dayofweek
which will give you a number refering to the day of the week (this changes based on your local settings, but usually Sunday is 0).
You could use this and an if
statement to decide whether the code should run.
Here's some code from many many moons ago:
@echo off
::
:: uses Windows Scripting Host
:: to set a variable to the current day number
:: for Win9x/ME/NT/W2K/XP
set amp=&
if not "%amp%"=="&" set amp=^^^&
set OF="%temp%.\tmp.vbs"
>%OF% echo n=weekday(now)
>>%OF% echo WScript.Echo "set day=" %amp% n
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
call "%temp%.\tmp.bat"
del "%temp%.\tmp.bat"
del %OF%
if "%day%"=="1" echo Sunday
if "%day%"=="2" echo Monday
if "%day%"=="3" echo Tuesday
if "%day%"=="4" echo Wednesday
if "%day%"=="5" echo Thursday
if "%day%"=="6" echo Friday
if "%day%"=="7" echo Saturday