Date And Time not getting Updated....!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
prash11
Posts: 21
Joined: 27 Apr 2012 01:38

Date And Time not getting Updated....!

#1 Post by prash11 » 17 May 2012 01:11

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#2 Post by foxidrive » 17 May 2012 03:19

Use delayed expansion.

prash11
Posts: 21
Joined: 27 Apr 2012 01:38

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

#3 Post by prash11 » 17 May 2012 03:22

how?
will it get updated?
because i am using that for 20 times

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#4 Post by foxidrive » 17 May 2012 03:58

Try this:

Code: Select all

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

prash11
Posts: 21
Joined: 27 Apr 2012 01:38

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

#5 Post by prash11 » 17 May 2012 04:26

it worked.
thnks foxidrive...!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#6 Post by Squashman » 17 May 2012 06:50

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?

Post Reply