Thursday, August 20, 2009

Playing with DATE and FOR in XP DOS

@echo off

rem for /F "tokens=1-4 delims=/ " %%i in ('date /t') do set dow=%%i && set month=%%j && set day=%%k && set year=%%l
rem for /F "tokens=1-4 delims=/ " %%i in ('date /t') do set dow=%%i && set date=%%j-%%k-%%l
rem for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set date=%%i-%%j-%%k

for /F "tokens=1-4 delims=/ " %%i in ("%DATE%") do (
set dow=%%i
set dom=%%j-%%k-%%l
set month=%%j
set day=%%k
set year=%%l
)

set datew=%DATE:~0,3%
set datem=%DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
set daten=%month%.%day%.%year%

echo %dow%
echo %datew%
echo %datem%
echo %daten%

No comments: