ECHO %DATE% %TIME% doesn't work in FOR loop

Tag(s):

ECHO %DATE% %TIME% doesn't work in FOR loop. Here is an example:

FOR /L %%V IN (1,1,3) DO (
  echo %DATE% %TIME%

  REM Wait 2 seconds
  PING 1.1.1.1 -n 1 -w 2000 >NUL
)

You have to put echo %DATE% %TIME% within a batch file(e.g ShowDateTime.bat) and call it from the loop as follows:

FOR /L %%V IN (1,1,3) DO (
  CALL ShowDateTime.bat

  REM Wait 2 seconds
  PING 1.1.1.1 -n 1 -w 2000 >NUL
)

ShowDateTime.bat contains the following:

echo %DATE% %TIME%