Computing.Net > Forums > Disk Operating System > Display date from a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Display date from a batch file

Reply to Message Icon

Name: Doug
Date: February 7, 2000 at 08:56:39 Pacific
Comment:

I'm writing a batch file that will run overnight on NT 4.0. I am redirecting the output from that file to a log.txt file. I would like to have the batch file write the current date to the screen (and thus be redirected to my log file). Hopefully there is a simple solution that requires no user interaction. I have tried the date command, but it prompts the user for the new date value, halting the script, and defeating the whole purpose of automating this task.

Please respond if you can help.

Thanks,
Doug



Sponsored Link
Ads by Google

Response Number 1
Name: Kazzy
Date: February 7, 2000 at 12:31:27 Pacific
Reply:

If Command Extensions are enabled the DATE command supports the /T switch which tells the command to just output the current date, without prompting for a new date. Hope this works for you.


0

Response Number 2
Name: peter perdok
Date: February 7, 2000 at 23:21:57 Pacific
Reply:

Q. How can I append the date and time to a file?

A. You can use the batch file below which will rename a file to filename_YYYYMMDDHHMM.

@Echo OFF
TITLE DateName
REM DateName.CMD
REM takes a filename as %1 and renames as %1_YYMMDDHHMM
REM
REM -------------------------------------------------------------
IF %1.==. GoTo USAGE
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP

DATE /T > %CURRDATE%
TIME /T > %CURRTIME%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j

Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

Echo RENAME %1 %1_%YYYYMMDD%%HHMM%
RENAME %1 %1_%YYYYMMDD%%HHMM%
GoTo END

:USAGE
Echo Usage: DateName filename
Echo Renames filename to filename_YYYYMMDDHHMM
GoTo END

:END
REM
TITLE Command Prompt

Example:

D:\Exchange> datetype logfile.log
RENAME logfile.log logfile.log_199809281630

Other date options include LOGTIME.exe which enables you to specify a string and then writes the time followed by the string to the file logtime.log at the current default directory.

The other option is NOW.exe which just replaces itself with the date and time, e.g.

D:\temp>now Batch complete
Mon Sep 28 15:54:19 1998 -- Batch complete

Both of the above utilities are part of the resource kit.

Another way is by using the following FOR command, a log file can be created using real dates.

rem created unique log filename, e.g. Wed0804
FOR /F "tokens=1-4 delims=/" %%i in ('date/t') do set file=%%i%%j%%k
Set LOG=drive:\directory\filename-%file%.log

The result is a file named filename-date.log.


But how do you redirect the output from a batch-file into a logfile ??


0

Response Number 3
Name: Doug
Date: February 8, 2000 at 13:56:34 Pacific
Reply:

Thanks for the help, that works fine.

To answer the last question, I redirect to a log file by simply using the > symbol like this.

c:\>batchfile > log.txt

Any text that batchfile would normally print to the screen goes into log.txt instead. If you do that with one > symbol, it overwrites log.txt. If you do that with two >> symbols, it appends to log.txt. Both ways will create the file if it doesn't exist.

Since I'm doing this through the NT Scheduler, I just appended the redirection to the command that NT has scheduled in the properties of that scheduled task.

Doug


0

Response Number 4
Name: SaGS
Date: February 11, 2000 at 06:00:19 Pacific
Reply:

A simple and basic DOS command for this:


echo.|date >filename.txt

Note: there's a period after the "echo"; there are no spaces around that period.

0

Response Number 5
Name: Mark
Date: February 23, 2000 at 12:37:49 Pacific
Reply:

create three batch files
create three batchfiles
batchfile 1
rem batchfile 1 exe.
rem this is the one you run
echo.| date| find "Current" > holddate.bat
call "holddate.bat"
current
<< this is the batchfiles name
rem batch "current.bat"
rename =recovend.txt %4%.txt
holddate.bat<< this is the third batchfile

Current date is Wed 02-23-2000


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

DOS Version Imaging Turbo Pascal 7.0 ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Display date from a batch file

User log in date from a batch file www.computing.net/answers/dos/user-log-in-date-from-a-batch-file/7783.html

reading a file from a batch file www.computing.net/answers/dos/reading-a-file-from-a-batch-file/765.html

Detect directory from a batch file.. www.computing.net/answers/dos/detect-directory-from-a-batch-file/4010.html