0

I'm trying to setup 7zip for automated backups but I'm having trouble with output file names.

I tried using the %date% command but it just made 2 directories within my backup.

C:\Users\Desktop\Sun 11\07\2010.7z

How can I make it just log the day and month?

C:\Users\Desktop\Sun 11-07-2010.7z

3 Answers 3

1

Try

7z a %DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.7z *.*     for (YYYY-MM-DD)

or

7z a %DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%.7z *.*     for (DD-MM-YYYY)

(*.* is the mask for the files to back up)

0

Are you using a bat-file? Look here http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/

0

You can use WMI to get your date details in a specific format. The problem with the output from date (and the %date% environment variable) is that it's very locale-specific.

If you execute:

wmic path win32_localtime get day^,month^,year^ /format:csv

you will see the output you need to process.

The following script will get you the yyyy-mm-dd format that you need (using the day of the week as the primary sort key is not a good idea):

@echo off
for /f "skip=2, tokens=2-4" delims=," %%a in ('wmic path win32_localtime get day^,month^,year^ /format:csv') do (
    set /a ymd = 10000 * %%c + 100 * %%b + %%a
)
set ymd=%ymd:~0,4%-%ymd:~4,2%%ymd:~6,2%
echo %ymd%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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