Solved

DOS WeekName

Posted on 2009-07-01
16
358 Views
Last Modified: 2012-06-21
I have windows 2003 R2 (SP2)

I am trying to ge the dat code ("mon,tue,wed") from dos.

I need it in a VAR  so i can do something.
If somone can help the script can end with ECHO %DAYNAME%

Can't make any registry changed or temp files.

Please advise !
0
Comment
Question by:myhc
[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
  • 6
  • 6
  • 2
  • +1
16 Comments
 
LVL 6

Expert Comment

by:vertsyeux
ID: 24752425
Hey dude/dudette.. Check out this previous EE posting..

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_21356348.html

Remember that if you change the environment in a batch file, the changes only exists for that batch file and files called from that file.. Once the file terminates, the changes are gone..
0
 
LVL 19

Expert Comment

by:deroode
ID: 24752429
In a batch file:

for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set dayname=%%u

If in a dosbox (not a batch file) change %%u in %u
0
 
LVL 7

Author Comment

by:myhc
ID: 24752443
vertsyeux:
That post I did review before but that script dosn't work.  not sure because of my veriosn.


deroode:
Result is "01" Required> "wed"
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 6

Accepted Solution

by:
vertsyeux earned 200 total points
ID: 24752480
Here's a WindosITPro article that purports to do what you want..

http://windowsitpro.com/Articles/Index.cfm?ArticleID=9177&DisplayTab=Article
0
 
LVL 6

Expert Comment

by:vertsyeux
ID: 24752500
Depending on what you are trying to do, I have a small C utility I wrote long ago for DOS, that will rename any file to the 3-letter day of week without changing the extension - we use this for renaming ZIP & 7zip archives on our clients' servers prior to uploading for a rolling 7-day offsite backup.. I'll post the source code if you want it..
0
 
LVL 19

Expert Comment

by:deroode
ID: 24752520
What do you get in a cmd prompt when you type

Date /t
0
 
LVL 7

Author Comment

by:myhc
ID: 24752533
What do you get in a cmd prompt when you type

Date /t

Just the date. 01/07/2009

0
 
LVL 6

Expert Comment

by:vertsyeux
ID: 24752534
he gets 01/07/2009 same as I do.. As stated above, macro is returning "01" and not "Wed"
0
 
LVL 7

Author Comment

by:myhc
ID: 24752546
From the link above this code works !!!!!

rem Create the date and time elements.
For /f "tokens=1-7 delims=.:/-, " %%i in ('echo exit^|command /K prompt $D $T ') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set ss=%%o
)
)
echo off
cls
Echo %DOW%


Can somone optimize it for me as I only need the DOW
I know to delete the "SET" but is the other bit optimized ??


Thanks in advance.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 50 total points
ID: 24752634
Reduced version. It is not very sophisticated, as it has to use command.com, which switches in 16bit DOS mode, but if you like it ...

rem Create the date and time elements.
For /f "tokens=1-7 delims=.:/-, " %%i in ('echo exit^|command /K prompt $D $T ') do ^
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do set dow=%%i
echo off
cls
Echo %DOW%

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24752647
Have you considered either the VBS or datex solutions in http://www.experts-exchange.com/Q_24447856.html yet?
0
 
LVL 6

Assisted Solution

by:vertsyeux
vertsyeux earned 200 total points
ID: 24752663
This is about as optimized as I can get it

@echo off

For /f "tokens=1-1 delims=.:/-, " %%i in ('echo exit^|command /K prompt $d ') do ^
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do set dow=%%i

Echo %DOW%
pause
0
 
LVL 7

Author Comment

by:myhc
ID: 24752870
My manager has just shown me up by writing this:

What do you think of that....
for /F "tokens=1,2,3 delims=/- " %%a in ("%DATE%") do (
set /A DD=%%a
set /A MM=%%b
set /A YY=%%c
)
 
 
SET /A LEAPDAYS=((%YY%-2000)/4)
 
SET /A YEARDAYS=((%YY%-2000)*365)+%LEAPDAYS%
 
IF %MM% == 1 SET /A MONTHDAYS=0
IF %MM% == 2 SET /A MONTHDAYS=31
IF %MM% == 3 SET /A MONTHDAYS=59
IF %MM% == 4 SET /A MONTHDAYS=90
IF %MM% == 5 SET /A MONTHDAYS=120
IF %MM% == 6 SET /A MONTHDAYS=151
IF %MM% == 7 SET /A MONTHDAYS=181
IF %MM% == 8 SET /A MONTHDAYS=212
IF %MM% == 9 SET /A MONTHDAYS=243
IF %MM% == 10 SET /A MONTHDAYS=273
IF %MM% == 11 SET /A MONTHDAYS=304
IF %MM% == 12 SET /A MONTHDAYS=334
 
 
SET /A TOTALDAYS=(%DD%+%MONTHDAYS%+%YEARDAYS%)
 
SET /A NOWEEKS=(%TOTALDAYS%/7)
 
SET /A DAYNUMBER=(%TOTALDAYS%-(%NOWEEKS%*7))
 
 
IF %DAYNUMBER% == 1 SET DATNAME=Sat
IF %DAYNUMBER% == 2 SET DATNAME=Sun
IF %DAYNUMBER% == 3 SET DATNAME=Mon
IF %DAYNUMBER% == 4 SET DATNAME=Tue
IF %DAYNUMBER% == 5 SET DAYNAME=Wed
IF %DAYNUMBER% == 6 SET DATNAME=Thu
IF %DAYNUMBER% == 7 SET DATNAME=Fri
 
ECHO OFF
CLS
ECHO DAY NAME:%DAYNAME%

Open in new window

0
 
LVL 6

Expert Comment

by:vertsyeux
ID: 24752896
It's... err.. substantial.. I think ... "thank heavens for cut&paste"
0
 
LVL 7

Author Comment

by:myhc
ID: 24753046
OK the code i submitted from my manager was wrong.

The code have been finished !!!!!!!!!!!!!!!!!!!!!!!!


AS BELOW !!!!
for /F "tokens=1,2,3 delims=/- " %%a in ("%date%") do (
set /A DD=%%a
set /A MM=%%b
set /A YY=%%c
)
 
 
SET /A LEAPDAYS=((%YY%-2000)/4)
 
SET /A YEARDAYS=((%YY%-2000)*365)+%LEAPDAYS%
 
IF %MM% == 1 SET /A MONTHDAYS=0
IF %MM% == 2 SET /A MONTHDAYS=31
IF %MM% == 3 SET /A MONTHDAYS=59
IF %MM% == 4 SET /A MONTHDAYS=90
IF %MM% == 5 SET /A MONTHDAYS=120
IF %MM% == 6 SET /A MONTHDAYS=151
IF %MM% == 7 SET /A MONTHDAYS=181
IF %MM% == 8 SET /A MONTHDAYS=212
IF %MM% == 9 SET /A MONTHDAYS=243
IF %MM% == 10 SET /A MONTHDAYS=273
IF %MM% == 11 SET /A MONTHDAYS=304
IF %MM% == 12 SET /A MONTHDAYS=334
 
 
SET /A TOTALDAYS=(%DD%+%MONTHDAYS%+%YEARDAYS%)
 
SET /A NOWEEKS=(%TOTALDAYS%/7)
 
SET /A DAYNUMBER=(%TOTALDAYS%-(%NOWEEKS%*7))
 
 
IF %DAYNUMBER% == 0 SET DAYNAME=Sat
IF %DAYNUMBER% == 1 SET DAYNAME=Sun
IF %DAYNUMBER% == 2 SET DAYNAME=Mon
IF %DAYNUMBER% == 3 SET DAYNAME=Tue
IF %DAYNUMBER% == 4 SET DAYNAME=Wed
IF %DAYNUMBER% == 5 SET DAYNAME=Thu
IF %DAYNUMBER% == 6 SET DAYNAME=Fri
 
ECHO OFF
CLS
ECHO DAY NAME:%DAYNAME%

Open in new window

0
 
LVL 7

Author Comment

by:myhc
ID: 25185822
BugFix = Code now 100% and used since 14/07/2009 without issue
echo off
 
ECHO ////////////////////////////////////////////////////
ECHO   // Title:		Day script. 	         //
ECHO   // Updated:		14/07/2009		//
ECHO   // Updated By:	Kyle Wadman		//
ECHO   // Verison:		1.0			//
ECHO ////////////////////////////////////////////////////
 
 
for /F "tokens=1,2,3 delims=/- " %%a in ("%date%") do (
SET /A DD=1%%a - 100
SET /A MM=1%%b - 100
SET /A YY=%%c
)
 
SET /A NUMYEARS=(%YY%-2000)
SET /A LEAPDAYS=((%YY%-2000)/4)
SET /A LEAPTEST=(%LEAPDAYS%*4)
 
IF %LEAPTEST% NEQ %NUMYEARS%  GOTO CONTINUE
 
IF %MM% LSS 3 SET /A LEAPDAYS=(%LEAPDAYS%-1)
 
:CONTINUE
SET /A YEARDAYS=((%YY%-2000)*365)+%LEAPDAYS%
 
IF %MM% == 1 SET /A MONTHDAYS=0
IF %MM% == 2 SET /A MONTHDAYS=31
IF %MM% == 3 SET /A MONTHDAYS=59
IF %MM% == 4 SET /A MONTHDAYS=90
IF %MM% == 5 SET /A MONTHDAYS=120
IF %MM% == 6 SET /A MONTHDAYS=151
IF %MM% == 7 SET /A MONTHDAYS=181
IF %MM% == 8 SET /A MONTHDAYS=212
IF %MM% == 9 SET /A MONTHDAYS=243
IF %MM% == 10 SET /A MONTHDAYS=273
IF %MM% == 11 SET /A MONTHDAYS=304
IF %MM% == 12 SET /A MONTHDAYS=334
 
 
SET /A TOTALDAYS=(%DD%+%MONTHDAYS%+%YEARDAYS%)
 
SET /A NOWEEKS=(%TOTALDAYS%/7)
 
SET /A DAYNUMBER=(%TOTALDAYS%-(%NOWEEKS%*7))
 
 
IF %DAYNUMBER% == 0 SET DAYNAME=Sat
IF %DAYNUMBER% == 1 SET DAYNAME=Sun
IF %DAYNUMBER% == 2 SET DAYNAME=Mon
IF %DAYNUMBER% == 3 SET DAYNAME=Tue
IF %DAYNUMBER% == 4 SET DAYNAME=Wed
IF %DAYNUMBER% == 5 SET DAYNAME=Thu
IF %DAYNUMBER% == 6 SET DAYNAME=Fri
 
CLS
ECHO DAY NAME:%DAYNAME%

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 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