easy question for you guys!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how can i get the date or time as a file name? this is what im trying to do:
echo hello world >>%date%.log
or
echo hello world >>%date%%time%.log
 
No before and no after is there in usenet; "this stuff, sort I, how should"
only is there.

/Yoda (aka Al)
 
Sorry if the "yoda-speak" threw you. It was an admitedly slightly snide
comment on your referring to another post relative to the one you replied to
as if we all see them in the same order.

/Al
 
Acttually I do it like this.

For Windows 2000 and later I use the parse function of the set command.

set MONTH=
set DAY=
set YEAR=
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YEAR=%DATE:~10,4%

Then you can:
echo Hello world >%YEAR%-%MONTH%-%DAY%

or put them together to make it easier. Include

set DateStmp=%YEAR%-%MONTH%-%DAY%
then
echo Hello World>%DateStmp%

Seems easier to me. I've done it with hours and minutes as well.

Stel
 
It's even easier if you omit the first three lines, which do nothing
useful.


Stel said:
Acttually I do it like this.
For Windows 2000 and later I use the parse function of the set command.
set MONTH=
set DAY=
set YEAR=
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YEAR=%DATE:~10,4%
Then you can:
echo Hello world >%YEAR%-%MONTH%-%DAY%
or put them together to make it easier. Include
set DateStmp=%YEAR%-%MONTH%-%DAY%
then
echo Hello World>%DateStmp%
 
Your right Gary. Old school I guess. I like to clear my variables by
omitting them just incase. I know once I declare them, even if they
were used, it is redefined. A little over kill I guess.

Stel
 
Gary Smith said:
It's even easier if you omit the first three lines, which do nothing
useful.

The calculations (especially for hours, minutes, seconds) should work with a
single snapshot of the DATE or TIME to avoid a mathematically significant
error in the somewhat unlikely event that the clock strikes midnight during
execution of the script. You could either assign this to a temp variable:

set thedate=%date%
set month=%thedate:~4,2%
<etc>

or force the command processor to provide the same date value for each
instance of %DATE% by enclosing the set of statements within parentheses:

(
set MONTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YEAR=%DATE:~10,4%
)

This assumes, of course, that delayed expansion has NOT been enabled.

/Al
 
Jerold Schulman said:
SETLOCAL ENABLEDELAYEDEXPANSION

See the delayed expansion topic at tip 5700 in the 'Tips & Tricks' at
http://www.jsiinc.com

In fact, in the context of my post, having delayed expansion on would not
have actually caused a failure, as that feature requires the use of the
alternate "!" variable delimiters, with the "%" delimiters still working as
per normal.

/Al
 
Back
Top