I am currently facing a weird issue while executing batch script. The date output works after 4th attempt of executing the script in the same command prompt instance.
Note : I am opening new instance of command prompt and then executing the batch script to fetch the date values but however the values does not appear and I need to execute the same script 4 times to get actual date values in the same instance of command prompt.
Below is the sample script.
@echo off
FOR %%x IN (1 2 3) DO (
echo submit > test.txt
(
echo testdata
) >> test.txt
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo Iteration :::: %%x
echo datestamp: "%datestamp%" , timestamp: "%timestamp%", fullstamp: "%fullstamp%"
)
Screen shot of the output: