# [SOLVED] windows 7 batch getting day of week (Moved from Vista/7)



## kdkingst

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


----------



## Michael_Larsen

*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


----------



## Ninjaboi

*Re: windows 7 batch getting day of week (Moved from Vista/7)*

Hello kdkingst, welcome to TSF!

You might be interested in checking out this thread, where someone was kind enough to post their batch code to do just that.


----------



## Excabus

*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.


----------



## jcgriff2

*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

`


----------



## kdkingst

*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.


----------



## sanya_y

*Re: windows 7 batch getting day of week (Moved from Vista/7)*

it's the answer what I want


----------

