How to access Day of Week in a batch file

In the past some experts at e-e helped me utilize data such as the day, month, and year in a batch file, as follows:

set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
if "%month:~0,1%"=="0" SET month=%month:~1,1%
set /a lastMonth=%month% - 1
if "%lastMonth:~1,1%"=="" SET lastMonth=0%lastMonth%
if "%lastMonth:~0,2%"=="00" SET lastMonth=12
if "%lastMonth%"=="12" SET /a year=%year% - 1

if %day%==29 SET /a day=28
if %day%==30 SET /a day=28
if %day%==31 SET /a day=28

set LM=%lastMonth%/%day%/%year%

rem If today is the first, clear the copy area...
if %day%==01 RD c:\osb\osbfiles /s /q

Now I need to also be able to access the Day of the Week,  I don't know what format it would be in, but I need to be able to say "something like":

if %dow%==Sunday copy .....

How can I do this?  TIA
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Here's a quick way:
FOR /F %%? IN ('CSCRIPT //NOLOGO "%TM_%"') DO (SET "WD_=%%?" &&(DEL "%TM_%"))

Open in new window

echo.|command /C date|find /i "current" >"%temp%\dow.txt"
for /f "tokens=1-4 delims=/ " %%i in (%temp%\dow.txt) do set DOW=%%l
echo %DOW%

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
Sorry I didn't get to this one sooner, but here's a simpler and faster way to get the day of the week (as a number, 0=Sunday) using WMI.  Going to post here for future reference and in case you find it useful.

set Sunday=0
for /f "skip=2 tokens=2 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set "DOW=%%A"
if %DOW% == %Sunday% (
  REM do Sunday processing here...

Open in new window

Lee W, MVPTechnology and Business Process AdvisorCommented:
Simpler still:

If /i "Sun"=="%date:~0,3" (
   REM Do Sunday stuff here

(This does assume your date command outputs in the format DAY MM/DD/YY)
Bill PrewIT / Software Engineering ConsultantCommented:
Agreed, but I have been burned by different date formats so try to avoid those. But certainly if you know the format on all computers a script needs to run on and don't expect it to change it can simplify things.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.