Solved

Windows Batch - Find Day of Week

Posted on 2010-08-19
7
1,183 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 51

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 51

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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now