The fact that you have %%f indicates that your echo command is in a FOR loop. The entire FOR loop is parsed immediately, and %DATE% expands during parsing. The command is not re-processed for each iteration, so you get the same value for each iteration. You get the value that existed before executing the FOR!
The solution is slow expansion. Put setlocal enableDelayedExpansion at the top of your script. Then use !DATE!_!TIME! instead of %DATE%_%TIME% . Deferred extension means that the extension occurs when the statement is executed, and not when it is parsed. There is a good explanation in the HELP system. Enter HELP SET or SET /? from the command line and find the section that deals with extension delay.
dbenham Sep 21 '12 at 12:29 2012-09-21 12:29
source share