How to log current timestamp inside a for loop in windows shell?

below is the output where i'm getting the same times tamp throughout the loop., where i'm expecting that to log the current time stamp..

C:\Users\ilango>for /l %i in (1,1,5) do echo [%DATE% %TIME%]  for %i

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 1
[Wed 01/13/2010  0:00:57.44]  for 1

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 2
[Wed 01/13/2010  0:00:57.44]  for 2

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 3
[Wed 01/13/2010  0:00:57.44]  for 3

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 4
[Wed 01/13/2010  0:00:57.44]  for 4

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 5
[Wed 01/13/2010  0:00:57.44]  for 5

C:\Users\ilango>

---------- Post updated at 12:22 AM ---------- Previous update was at 12:07 AM ----------

[/COLOR]Ok, found a solution myself..

C:\Users\ilango\test>for /l %i in (1,1,5) do (VER | TIME | FINDSTR /R /C:"[0-9]"
) & echo for %i

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 1
The current time is:  0:24:46.78
for 1

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 2
The current time is:  0:24:46.82
for 2

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 3
The current time is:  0:24:46.87
for 3

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 4
The current time is:  0:24:46.90
for 4

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 5
The current time is:  0:24:46.95
for 5

C:\Users\ilango\test>

but still, i don't understand why the earlier one didn't work!!?

Hi,
I don't think I can add much to this observation, other than it is an example of how absurd the cmd shell is! I have wrestled with this from time to time. It should be such an easy thing to just ask for the current time, right?

The env variables DATE and TIME are set at .cmd-file execution start. But not entirely! If You have a script that runs over several minutes it *may* change! Or if You make a "call" to another script (that does echo %DATE% %TIME%), but they may simply
inherit the callers values, I don't recall correctly right now, but please try :slight_smile:

If You use TIME You get an interactive command, but it shows You the "correct" time. If You use TIME /T it will only display HH:MM !
If You use TIME < NUL (instead of giving it the output of VER which is just garbage for the TIME command, that's why it works) it will give You an ugly prompt, so You will have to filter it.

So bloody stupid!

And don't get me started on such a simple thing as sleep... arrrrgh!

/Grrrr