Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 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.


share|improve this question
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

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%"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .