Does the following code answer your question?
Code: Select all
:: Generic date parser
:: Sets %dd% (01-31), %mm% (01-12) & %yy% (4 digit)
if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (
set %%a=%%d
set %%b=%%e
set %%c=%%f
set toks=
)
)
if %yy% LSS 100 set yy=20%yy%
echo Year is %yy%, Month is %mm%, Day is %dd%
The indentation for the second FOR command could have been written, much less intelligibly to a human, as:
Code: Select all
for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (set %%a=%%d&set %%b=%%e&set %%c=%%f&set toks=)
This sort of code structure can require pairs of double quotes or pairs of brackets to prevent a stray trailing blank appearing at the end of a variable.