Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to run a daily incremental backup and append the day of the week to the file name so I end up with:

backup_mon.bak
backup_tue.bak

etc.

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

How do I go about this?

share|improve this question
add comment

3 Answers

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.