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 am trying to create a batch file to backup my data at regular intervals in Windows using a batch script.

I need date parameter and the fields from the displayed format (Month, day and year). everything works fine when I am using delimiters initially. But when I change the date format from dd-mm-yyyy to yyyy-mm-dd everything fails.

So is there any generic format to extract the fields(mm,dd,yyyy) even-though the format varies.

Thanks.

share|improve this question
2  
This is hard to follow as-is, Can you post the batch code you have so far? –  Ƭᴇcʜιᴇ007 Mar 29 '13 at 20:21
    
I do believe there is a similar question on Stack Overflow, I just can't find it yet. –  Prof Pickle Mar 30 '13 at 9:12
    
While it might be possible to cook something up (which will no doubt make your batch files even more complex unnecessarily), how often do you need to change your system's date format in Control Panel anyway? –  Karan Mar 31 '13 at 15:12

1 Answer 1

The only safe way to get a kind of generic date is the following (hopefully independent of local settings):

@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 "dd MM yyyy" >nul
set "cdate=%date%"
reg add "HKCU\Control Panel\International" /f /v sShortDate /d "%ssShortDate%" >nul
for /f "tokens=1-3" %%i in ("%cdate%") do set "day=0%%i"&set "month=0%%j"&set "year=%%k"
set "day=%day:~-2%"
set "month=%month:~-2%"
echo.%year%-%month%-%day%
endlocal
share|improve this answer

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.