Solved

Windows Batch - Find Day of Week

Posted on 2010-08-19
7
1,204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Author Comment

by:elwayisgod
ID: 33477403
result is:

DOW=~16,3

result should be: Thursday
0
 
LVL 56

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 56

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 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