0

I am using the robocopy command to create a backup system, I have successfully managed to copy the folders, but the date stamp is wrong. The folders are prefixed with the date and time .

The robocopy command is this:

robocopy U:\Data\  X:\Private\Backups\FolderName_%date:/=-%-(%time::=-%) /e

The out of the folder is displayed like this:

FolderName_09-11-2013-(20-24-06.60)

The only thing I want to change is the date, I want to show the month as a string with only the first 3 characters like Oct.

Can someone please guide me. Thanks.

4

Please note that using %date% is very Windows-version and region depended. Each language/region has its own settings and the users can change this too. Not really a reliable way to get the date.

The most effective way to get the correct date is with wmic OS Get localdatetime. I'm not sure if you can get the month-name the same way so here i just used some if-statements to get the month-name:

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set year=%dt:~0,4%
set month=%dt:~4,2%
set day=%dt:~6,2%
if %month%==01 set month=jan
if %month%==02 set month=feb
if %month%==03 set month=mar
if %month%==04 set month=apr
if %month%==05 set month=may
if %month%==06 set month=jun
if %month%==07 set month=jul
if %month%==08 set month=aug
if %month%==09 set month=sep
if %month%==10 set month=oct
if %month%==11 set month=nov
if %month%==12 set month=dec
robocopy U:\Data\  X:\Private\Backups\FolderName_%day%-%month%-%year%-(%time::=-%) /e

I know it's not a "one-liner" but i think it's the most reliable way to get the date.

-1

This short script will do the exact same thing as the above without the IF statements.

@echo off &setlocal
for /f "tokens=2*" %%a in ('reg query "HKCU\Control Panel\International" /v sShortDate^|find "REG_SZ"') do set "ssShortDate=%%b"
reg add "HKCU\Control Panel\International" /f /v sShortDate /d "ddd MMM" >nul
set "dowlm=%date:~4,3%
echo %dowlm%
endlocal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy