Reputation: 17
Can someone tell me what's the problem with the below batch script? I don't get MYTIME in the final output.
@ECHO ON
SET CURRENTTIME=%TIME%
IF "%CURRENTTIME:~0,1%"==" " (SET CURRENTTIME=0%CURRENTTIME:~1%)
FOR /F "tokens=1-2 delims=/." %%a in ("%CURRENTTIME%") do (set MYTIME = %%a)
FOR /F "tokens=2-4 delims=/ " %%A IN ('DATE /T') DO (SET TIMESTAMP=%%C-%%A-%%B)
ECHO %TIMESTAMP%-%MYTIME%
PAUSE
Let us say the Date is 21 July 2015 and time is 04h:05m:06s.5ms.
The output I expect is 2015-07-21-04:05:06
But the output is 2015-07-21-
Upvotes: 0
Views: 38
Reputation: 70923
set MYTIME = %%a
space included in variable name....^ ^.. Space included in value
So you end with %MYTYME %
variable. Better use
set "MYTIME=%%a"
Upvotes: 1