Tech Support banner
Status
Not open for further replies.
1 - 7 of 7 Posts

·
Registered
Joined
·
2 Posts
Discussion Starter · #1 ·
I've seen many methods of getting the day of week in a batch program. The following almost works while most of the others are for older systems.
for /f %%i in ('wmic path win32_localtime get dayofweek') do set wd=%%i
Does get the day of week but overrides it with space before it exits the loop. Iteration 1 is the literal day of week. Iteration 2 is the number 2 which i want but it does a third iteration which returns a space. When it exits the loop i have a space in the field wd. Anyone know how I can get at the answer I want?? Thanks
 

·
Visiting Expert, Microsoft Support Team
Joined
·
656 Posts
Re: windows 7 batch getting day of week (Moved from Vista/7)

Hi kdkingst. Welcome to TSF! :wave:

Am I to understand that you want to run a batch file only on certain days of the week? I'm not quite sure I follow what you're trying to do.

Good day!

Mike
 

·
Registered
Joined
·
137 Posts
Re: windows 7 batch getting day of week (Moved from Vista/7)

Code:
set DIRDATE=
set DIRDATE=%DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
That may or may not help, I use this snip of batch code in one of my programs, it sets part of the directory it creates name using portions of the data. After the ~ the number designates the starting characters, then the number after the following comma designates the ammount of characters to select in defining DIRDATE variable.

So by default the DATE command shows the current date with the three first letters of the day's date, then the DD/MM/YYYY as well. If I wanted the first three letters of the days name, I wanted to echo the first three letters of the days name I would use,

Code:
echo %DATE:~0,3%
This will display "Tue" without quotations.

You could then use some kind of IF statement or something to define a second variable. Say something along the lines of,

Code:
SET MYDATE=%DATE:~0,3%
IF %MYDATE% == Mon echo Mondayday
IF %MYDATE% == Tue echo Tuesday
IF %MYDATE% == Wed echo Wednesday
IF %MYDATE% == Thu echo Thursday
IF %MYDATE% == Fri echo Friday
IF %MYDATE% == Sat echo Saturday
IF %MYDATE% == Sun echo Sunday
More likely you want to utilize the day within a variable,

Code:
IF %MYDATE% == Mon SET MYDATE2=Monday
Similar but different from the script above.
 

·
Administrator, Manager, Microsoft Support, MVP
Joined
·
34,393 Posts
Re: windows 7 batch getting day of week (Moved from Vista/7)

Using WMI -
Code:
@echo off  
set daysofweek=Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday  
for /F "skip=2 tokens=2-4 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set daynumber=%%A  
for /F "tokens=%daynumber% delims=," %%B in ("%daysofweek%") do set day=%%B
echo %daynumber% > c:\0  & echo %day% >> c:\0 & start notepad c:\0
A Notepad will open with the day #; next line = of the week.

Batch file - http://sysnative.com/0x8/wmi_dayofweek_nameofday_jcgriff2_.bat.zip

Regards. . .

jcgriff2

`
 

·
Registered
Joined
·
2 Posts
Discussion Starter · #6 ·
Re: windows 7 batch getting day of week (Moved from Vista/7)

Thanks for the replies - I was able to get a solution out of that.
 
1 - 7 of 7 Posts
Status
Not open for further replies.
Top