I have scripted DTYMD.bat to returns today's 4 digit year, 2 digit month, and 2 digit day, regardless of your date format.

DTYMD.bat retrieves your date format from the iDate Value Name, using REG.EXE, built into Windows XP and Windows Server 2003, or REG.EXE from the Windows 2000 Support Tools on the CD-ROM, which must be available in your PATH.

The syntax for using DTYMD.bat is:

\[call\] DTYMD YYYY MM DD

Where:

<b>YYYY</b>  is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a> that will contain today's 4 digit year.
<b>MM</b>    is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a> that will contain today's 2 digit month.
<b>DD</b>    is a <a href="/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a> that will contain today's 2 digit day.
DTYMD.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: DTYMD YYYY MM DD&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%x in ('date /t') do (
 set /a p1=10000%%x%%10000
 set /a p2=10000%%y%%10000
 set /a p3=10000%%z%%10000
)
if %p1% LSS 10 set p1=0%p1%
if %p2% LSS 10 set p2=0%p2%
if %p3% LSS 10 set p3=0%p3%
set df=3
for /f "Tokens=2,3" %%x in ('REG QUERY "HKCU\Control Panel\International" /V iDate^|find /i "REG_SZ"') do set df=%%y
if "%df%" EQU "0" set MM=%p1%&set DD=%p2%&set YY=%p3%&goto dayn
if "%df%" EQU "1" set DD=%p1%&set MM=%p2%&set YY=%p3%&goto dayn
if "%df%" EQU "2" set YY=%p1%&set MM=%p2%&set DD=%p3%&goto dayn
set YY=0000&set MM=00&set DD=00
:dayn
endlocal&set %1=%YY%&set %2=%MM%&set %3=%DD%