Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use the numerical part of the output of "wmic path win32_localtime get dayofweek" to number backup files. Something along the lines of:

FOR /F "tokens=2 delims=\n" %%DoW IN ('wmic path win32_localtime get dayofweek') DO (echo %%DoW)

Except that the above does not work. Any help would be much appreciated.

share|improve this question
Seems I have a solution: -- is there a non-Assembler solution, though? ;> – aelfinn Nov 9 '10 at 15:11
Note that that won't work on 64-bit Windows, as you cannot run 16-bit programs there. I'd consider it a poor solution. – Joey Nov 9 '10 at 22:37

In the newer MS Windows OS's, which includes Vista and Windows 7, the "date" command does not return a day of week but you can still put the day into a variable by using the following in a batch script:

@echo off & Setlocal 
Set "_=mon tues wed thurs fri sat sun" 
For /f %%# In ('WMIC Path Win32_LocalTime Get DayOfWeek^|Findstr [1-7]') Do ( 
        Set DOW=%%#)
:: now lets display the day of week on the screen 
echo "%DOW%"

For Windows 2K and XP you can parse the day from the "date" command by using the following in a batch script:

@echo off
echo.|date|find "is:" >Get.bat
findstr "is:" get.bat > Str
for /f "tokens=5 delims= " %%d in (str) do set day=%%d
del get.bat
del str
:: echo day of week to the screen
echo Today is %day%
share|improve this answer
Sundays will have 0, not 7, so Findstr [1-7] will not work. – Michel de Ruiter Jul 4 at 10:23

Variables in a FOR loop can only be single character. The delims you have indicates a literal backslash and "n" instead of a newline.

@echo off
SETLOCAL enabledelayedexpansion
SET /a count=0
FOR /F "skip=1" %%D IN ('wmic path win32_localtime get dayofweek') DO (
    if "!count!" GTR "0" GOTO next
    ECHO %%D
    SET /a count+=1
share|improve this answer
Thanks, I’ll give this a try as soon as I can. In the meantime, can I ask a) where I could have found the information regarding single-character variables in FOR loops, b) what your second line is for, and c) whether there is a term for ‘newline’ to be used in ‘delims’? :) – aelfinn Nov 9 '10 at 23:49
help for has the information regarding single character variables: "%variable Specifies a single letter replaceable parameter." The second line enables delayed expansion of variables so !count! is evaluated when it's executed (while %count% would be evaluated when the line containing it is read and not re-evaluated at each step of the loop). See 'help setlocal' and 'help set'. Supposedly ^T (Ctrl-t) or (Alt+0182) can be used for newlines, but apparently not in the case of delims. If you can, use PowerShell instead of CMD for scripts. – Dennis Williamson Nov 10 '10 at 0:07
for /f "skip=1 tokens=2 delims=," %i in ('wmic path win32_localtime get dayofweek /format:csv') do set DOW=%i
echo %DOW%
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.