@echo off
if "%1"=="[(" goto parse
echo.|date|find "Current" > _getdate.bat
echo set _dw=%%3> current.bat
echo set _date=%%4>> current.bat
call _getdate.bat
echo.|date|find "Enter" > _getdfmt.bat
echo set _dfmt=%%3> enter.bat
call _getdfmt.bat
echo.|time|find "Current" > _gettime.bat
echo set _time=%%3> current.bat
call _gettime.bat
echo _|choice /c%_dfmt%%_date%_%_time%_ @%0 > _parse.bat
%comspec% /e:2048 /c _parse.bat
goto end
:parse
set _dt1=_%2%3
set _dt2=_%5%6
set _dt3=_%8%9
for %%t in ([,Y,Y,-,M,M,-,D,D,]) do shift
set _vdt=
:loop1
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop1
set %_dt1%=%_vdt%
set _vdt=
:loop2
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop2
set %_dt2%=%_vdt%
set _vdt=
:loop3
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop3
set %_dt3%=%_vdt%
set _vdt=
:loop4
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop4
set _HH=%_vdt%
set _vdt=
:loop5
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop5
set _MN=%_vdt%
set _vdt=
:loop6
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop6
set _SS=%_vdt%
set _vdt=
:loop7
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop7
set _CS=%_vdt%
echo DTN:%_YY% %_MM% %_DD% %_HH% %_MN% %_SS% %_CS%
:end
@echo off
if "%1"=="[(" goto parse
echo.|date|find "Current" > _getdate.bat
echo set _dw=%%3> current.bat
echo set _date=%%4>> current.bat
call _getdate.bat
echo.|date|find "Enter" > _getdfmt.bat
echo set _dfmt=%%3> enter.bat
call _getdfmt.bat
echo.|time|find "Current" > _gettime.bat
echo set _time=%%3> current.bat
call _gettime.bat
echo _|choice /c%_dfmt%%_date%_%_time%_ @%0 > _parse.bat
%comspec% /e:2048 /c _parse.bat
goto end
:loop
set _vdt=
:loop1
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto loop1
set %_set%=%_vdt%
goto %next%
:parse
set _dt1=_%2%3
set _dt2=_%5%6
set _dt3=_%8%9
set fgf=%4
for %%t in ([,Y,Y,-,M,M,-,D,D,]) do shift
:dt1
set _set=%_dt1%
set next=dt2
goto loop
:dt2
set _set=%_dt2%
set next=dt3
goto loop
:dt3
set _set=%_dt3%
set next=hh
goto loop
:hh
set _set=_hh
set next=MN
goto loop
:mn
set _set=_mn
set next=ss
goto loop
:ss
set _set=_ss
set next=cs
goto loop
:cs
set _set=_cs
set next=echo1
goto loop
:echo1
echo DTN:%_YY% %_MM% %_DD% %_HH% %_MN% %_SS% %_CS%
:end
@echo off
if "%1"==":" goto %2
echo.|date|find "Current" > _getdate.bat
echo set _dw=%%3> current.bat
echo set _date=%%4>> current.bat
call _getdate.bat
echo.|date|find "Enter" > _getdfmt.bat
echo set _dfmt=%%3> enter.bat
call _getdfmt.bat
echo.|time|find "Current" > _gettime.bat
echo set _time=%%3> current.bat
call _gettime.bat
echo _|choice /c"%_dfmt%%_date%_%_time%" @%0 : parse > _parse.bat
%comspec% /e:2048 /c _parse.bat
call _setdt.bat
for %%e in (_date _dfmt _time) do set %%e=
for %%f in (_*.bat enter.bat* current.bat*) do del %%f
echo DTN:%_YY%-%_MM%-%_DD% %_HH%:%_MN%:%_SS%.%_CS%
goto end
:parse
set _me=%0
shift
shift
set _tok=%2%3 %5%6 %8%9 HH MN SS CS
for %%t in ([,Y,Y,-,M,M,-,D,D,]) do shift
:NextToken
set _vdt=
:GetToken
shift
set _tmp=%_vdt%
for %%t in (1,2,3,4,5,6,7,8,9,0) do if "%1"=="%%t" set _vdt=%_vdt%%1
if not "%_vdt%"=="%_tmp%" goto GetToken
if "%1"=="" goto end
call %_me% : SetToken %_tok%
goto NextToken
:SetToken
set _tok=%4 %5 %6 %7 %8 %9
echo set _%3=%_vdt%>> _setdt.bat
goto end
:end
@echo off
if "%1"==":" goto %2 (subroutine handler at %2)
echo.exit|%comspec%/e:4096/k prompt set v=$d $t$_:>_tm.bat
call _tm.bat
echo.%v%&|%comspec%/e:4096/c %0 : Parse>_tm.bat
for %%p in (_tm.bat* _tmset.bat*) do call %%p
echo.Note that d1 d2 and d3 are in your system date order
echo.DTN:d1=%d1% d2=%d2% d3=%d3% hh=%hh% mm=%mm% ss=%ss% cs=%cs%.
for %%e in (v d1 d2 d3 hh mm ss cs) do set %%e=
for %%f in (_tm.bat* _tm.tmp* _tmset.bat*) do del %%f
goto end
:Parse (usage: call %0 : Parse +input redirect date/time)
set me=%0
set tok=d1 d2 d3 hh mm ss cs
set d1=
:NextToken
for %%v in (v1 v) do set %%v=
choice /c&0123456789 /n>_tm.tmp
for %%n in (0 1 2 3 4 5 6 7 8 9) do if errorlevel 77%%n set v=%%n
if not errorlevel 2 %me% : SetToken %tok%
find ""<_tm.tmp>nul
if not errorlevel 1 if not "%d1%"=="" call %me% : SetToken %tok%
set d1=%d1%%v%
goto NextToken
:SetToken
set tok=%4 %5 %6 %7 %8 %9
echo set %3=%d1%>> _tmset.bat
set d1=
goto end
:end (end-of-file)