Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo date into a log from a cmd file

Status
Not open for further replies.

2ITLTD

Technical User
Sep 19, 2002
17
GB
I am trying to echo the current date into a log file but this does not appear to work on NT4 but works on W2K.

echo %date% >> MyLogfile.txt works on W2K if I do the same on NT4 I get a blank echoed into the log file.

I also tried echo %date%/T and this does the same. Can any help, or is it an environmental issue.????
 
This is an environmental issue. Windows 2000 sets the date variable automatically, but NT does not.

All you are doing with the echo command is telling the command processor to print that variable. When the variable is not set, there is nothing to print.

What you should try in NT is the date command instead of echo. I think you will find the following does what you want.

date /T >> MyLogfile.txt
 
this may be useful to you

FOR /F "tokens=2-4 delims=/ " %%a IN ('DATE /T') DO SET DATE=%c%%b%%a

where %c% is year, %b% is month and %a% is day

i.e for 21 nov 2003
%c% is 2003
%b% is 11
%a% is 21

you may find this usefull if you need the date in a variable

I use it to create log files with current date on using this

FOR /F "tokens=2-4 delims=/ " %%a IN ('DATE /T') DO SET LOGNAME=batchlog%%c%%b%%a.LOG

echo running batch file > %LOGNAME%
.... etc

regards

Neil
 
Ah yes, I already have tried that, what I missed out in my question was that I want to see the date and time and some text on the same line in a log file.

e.g. date /T - time /T - Started Processing Data... >>%MyLog%
 
if you have the nt resource kit use the now command

like this

NOW STAGE 1 - Transfer any waiting files from gateway PC to %AGNDIR% >>%LOGNAME%

will give you current date/time plus the comment

 
What's wrong with good old:

echo.|date >> logfile.txt

This also works with the Time command.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top