Solved

Windows Batch - Find Day of Week

Posted on 2010-08-19
7
1,188 Views
Last Modified: 2012-05-10
Hi,

I have the below batch script to create the 'DOW' variable.  However when I run it, it's choking on the 4th lineon the 'Command' part.  Not sure what is wrong.  Any help?  Prefer to keep this Windows Batch.  Running on Win Server 2003 R2.


REM Set the Day of Week (DOW) Variable
:: setDOW.bat
@echo off
Echo.|Command /C Date>DOW
set /p today=<DOW
set DOW=%today:~16,3%
echo DOW=%DOW%
:: DONE
0
Comment
Question by:elwayisgod
  • 4
  • 2
7 Comments
 

Author Comment

by:elwayisgod
ID: 33477403
result is:

DOW=~16,3

result should be: Thursday
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 33477477
If you do the following command at a DOS prompt, what does it display?

ECHO %DATE%

~bp
0
 

Author Comment

by:elwayisgod
ID: 33477495
'Command' is not recognized as an internal or external command,
operable program or batch file.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:elwayisgod
ID: 33477503
X:\Sam_LREF\EssbaseBackup\maxl>echo %Date%
Thu 08/19/2010
0
 

Author Comment

by:elwayisgod
ID: 33477536
I just want the 'Thu' not the rest of it. So my results would always be:

Mon
Tue
Wed
Thu
Fri
Sat
Sun
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 125 total points
ID: 33477569
In a BAT file, this is all you should need:

@echo off
for /F "tokens=1" %%A in ("%DATE%") do set DOW=%%A

~bp
0
 
LVL 2

Expert Comment

by:PeterGillett
ID: 33477666
If your echo %date% gives Thu 08/19/2010

then you should be able to use:

SET DOW=%date:~0,3%
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question