Page 1 of 1

Date And Time not getting Updated....!

Posted: 17 May 2012 01:11
by prash11
hi everyone,
i am calling many batch file from one batch file.
the one batch file from which i am calling other batch files contains this
echo %DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% Starting the 1st process...!
2nd process...!
nth process...!

what happens here is windows calculates this value only first time and prints same value every time.
and i am using that echo statement for 20 times.
so 20 times same time stamp gets printed.
and i am not able to see what time is taken by which process.
so i want the updated time and date for every process.
i want this pattern 2012-05-15 13:59:01.
i even stored it in a variable and tried to print....but i got same output...!
any suggestions?
thank you.

Re: Date And Time not getting Updated....!

Posted: 17 May 2012 03:19
by foxidrive
Use delayed expansion.

Re: Date And Time not getting Updated....!

Posted: 17 May 2012 03:22
by prash11
how?
will it get updated?
because i am using that for 20 times

Re: Date And Time not getting Updated....!

Posted: 17 May 2012 03:58
by foxidrive
Try this:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
(
echo !time!
ping -n 10 localhost >nul
echo !time!
)
pause

Re: Date And Time not getting Updated....!

Posted: 17 May 2012 04:26
by prash11
it worked.
thnks foxidrive...!

Re: Date And Time not getting Updated....!

Posted: 17 May 2012 06:50
by Squashman
prash11,
Kind of the same thing as your previous thread. '
viewtopic.php?f=3&t=3297
Do you understand now when you have to use delayed expansion?