Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want to run a daily incremental backup and append the day of the week to the file name so I end up with:



Not really bothered about what exactly is appended - 0 - 6 is fine.

How do I go about this?

share|improve this question

Take a look at Advanced date and time math in batch files. You find there a subroutine which converts a date to the Julian calendar and another one which will tell you the weekday.

share|improve this answer

Since you're using this for a backup, you are presumably running the script with admin privileges, in which case you can use wmic.

for /F "tokens=2 skip=2 delims=," %%D in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do @echo %%D

Will give you the day of week as a number (Monday=1).

share|improve this answer

If you have no problem calling an external script, you can use VBScript to get the day of week very easily:

the VBScript code:

wscript.echo WeekdayName(Weekday(Date))

Calling it and using it in your filename:

for /f "delims=" %%a in ('cscript /nologo dayofweek.vbs') do @set myvar=%%a
set filename=backup_%myvar%.bak

then later in your script you can use the variable %filename% to access it. If I ran this today for example, it would create a file called backup_Sunday.bak. Ensure the VBscript file is in the same directory as the batch script.

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.