0

here is what I have so far but not being an expert don't know where to go from here

for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set WD=%%i
) 
for /f "tokens=1-2 delims=," %%a in ("Sat,Sun") do if not %%a==%WD%  Echo %WD%  
Squashman
  • 13,649
  • 5
  • 27
  • 36
  • Possible duplicate of [Setting a windows batch file variable to the day of the week](https://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week) – phuclv Jun 05 '18 at 01:49
  • using `date` is not safe because it depends on the locale settings – phuclv Jun 05 '18 at 01:49

1 Answers1

0

The tokens keyword extracts one or more tokens from a text file line or string based on a delimiter, and assigns them to alphabetically subsequent variables, once per line, and you only need the first token on the line. Using a space as the delimiter breaks the date (returned by date /t as "Wed 11/01/2017") after the day of week. Use the set command to assign the value to an environment variable, WD.

for /F "tokens=1 delims= " %%i in ('date /t') do set WD=%%i

Testing in batch files is done by if with environment variable expansion delimited by % around the environment variable. Matches are literal, so quotes must be placed around the variable value and the match value.

On Sunday, don't do anything so exit the batch file with exit /b.

if "%WD%" == "Sun" exit /b

On Saturday, run the Saturday task and the rest of the week, run the weekday task.

if "%WD%" == "Sat" (
    rem do Sat
) else (
    rem do Mon-Fri
)
NetMage
  • 26,163
  • 3
  • 34
  • 55
  • Just checking back on the edit history. What was presented for review (that I tagged) was your first edit, not current one. You had already corrected your initial answer by the time I flagged it in the Review pages. – DiskJunky Nov 01 '17 at 22:49
  • Thanks for the input I have it now – F. Marler Nov 02 '17 at 14:40