Because the idea of tearing %DATE%
and %TIME%
apart and mashing them back together seems fragile at best, here's an alternative that uses a powershell oneliner:
for /f %i in ('powershell -c "get-date -format yyyy-MM-dd--HH-mm-ss"') do @set DATETIME=%i
set LOGFILE=my-script-%DATETIME%.txt
Reference for get-date
is here, with format options for both .NET-style and UNIX-style.