Time and Date Stamping to File

  • Thread starter Brendan Crisler
  • Start date
B

Brendan Crisler

I need to find a way to append a time and date stamp onto
a file. I want to be able to script this in an MS-DOS
command target in the Startup folder. Basically, I want
to start a program when windows starts, and I want this
program to capture information and send it to a newly
created text file. I need this text file to be unique
every time the target command is run and that is why I
want the time and date stamps to be appended to it.

I know it can be done on a linux or unix based machine and
I know the scripting for that, but I have not found a way
to do it in DOS.

I would appreciate any help.

Thanks.
 
T

Torgeir Bakken \(MVP\)

Brendan said:
I need to find a way to append a time and date stamp onto
a file. I want to be able to script this in an MS-DOS
command target in the Startup folder. Basically, I want
to start a program when windows starts, and I want this
program to capture information and send it to a newly
created text file. I need this text file to be unique
every time the target command is run and that is why I
want the time and date stamps to be appended to it.
Hi

One way is to from your batch file create a temporary vbscript
file and pick up the result, more here:

http://groups.google.co.uk/[email protected]

and
http://www.jsiinc.com/SUBR/tip8600/rh8600.htm


You can do it with "pure" batch file as well, using e.g the batch date
time functions from Ritchie Lawrence batch library available at
http://www.commandline.co.uk/lib
 
S

Stel

Here is one way. Use the parse function of the set command.


set MONTH=
set DAY=
set YEAR=
set HOUR=
set MIN=
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YEAR=%DATE:~10,4%
set HOUR=%TIME:~0,2%
set MIN=%TIME:~3,2%

Now just put the variables together like.
dir c:\ >FilesOnCdrv-%YEAR%-%MONTH%-%DAY%-%HOUR%-%MIN%

Or you could make a new varilables for several

set datestmp=%YEAR%-%MONTH%-%DAY%-%HOUR%-%MIN%

and use it like this
dir c:\ >FilesOnCdrv-%datestmp%

Hope this helps.

Stel
 
G

Gary Smith

Why not omit the first five lines? They don't accomplish anything.


Stel said:
Here is one way. Use the parse function of the set command.
set MONTH=
set DAY=
set YEAR=
set HOUR=
set MIN=
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YEAR=%DATE:~10,4%
set HOUR=%TIME:~0,2%
set MIN=%TIME:~3,2%
Now just put the variables together like.
dir c:\ >FilesOnCdrv-%YEAR%-%MONTH%-%DAY%-%HOUR%-%MIN%
Or you could make a new varilables for several
set datestmp=%YEAR%-%MONTH%-%DAY%-%HOUR%-%MIN%
and use it like this
dir c:\ >FilesOnCdrv-%datestmp%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top