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:

setlocal
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
LVL 3
sasllcAsked:
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.

NVITCommented:
Here's a quick way:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET TM_=%TEMP%\_TMP$.VBS
>%TM_% ECHO WSCRIPT.ECHO WEEKDAYNAME(WEEKDAY(DATE),TRUE)
FOR /F %%? IN ('CSCRIPT //NOLOGO "%TM_%"') DO (SET "WD_=%%?" &&(DEL "%TM_%"))
ECHO %WD_%

Open in new window


Or...
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

0

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 PrewCommented:
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

~bp
0
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)
0
Bill PrewCommented:
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.

~bp
0
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.