I had the painful experience of recently having to update some windows .bat scripts with some new functionality…. I’ve pleasantly re-affirmed why I DON’T WORK ON A WINDOWS PLATFORM!…

In any event, for any of you poor suckers that do and need access to datetime components within a batch, here’s an ugly solution… If you know of a better way.. I’m all ears!

echo %DATE% %TIME% > datefile.txt
REM parse Datefile (format mon MM-DD-YYYY (US date and time setting default))
For /F "tokens=2,3,4 delims=/ " %%a in (datefile.txt) do (set CurrentMonth=%%a&& set currentDate=%%b&& set /A currentYear=%%c)
For /F "tokens=3,4,5 delims=: " %%a in (datefile.txt) do (set CurrentHour=%%a&& set currentMinute=%%b&& set currentSecond=%%c)
echo Timstamp is: %CurrentYear%%CurrentMonth%%CurrentDate%%CurrentHour%%CurrentMinute%%CurrentSecond%

God help us all thats fugly!

Post to Twitter Tweet This Post