Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Windows Batch - Find Day of Week

Posted on 2010-08-19
7
Medium Priority
?
1,228 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 59

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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 59

Accepted Solution

by:
Bill Prew earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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