How do I make a directory = date? md %date% ?

A

adeveloper

Hi,

Is there a DOS command in windows 2000 to make a directory equal to todays
date in something like ISO format (YYYYMMDD - e.g. 20050519 for todays
date).

I tried
md "%date%"
but because of the /s in the date format it it made:
Thu 19\05\2005
which doesn't work because I need year first.

I guess maybe I could change the date format then change it back
aftwarwards?

PS: Why does SET /? give you heaps of detail - but in the Windows 2000 help
there is f**k all on set...?

Pete
 
P

Pegasus \(MVP\)

adeveloper said:
Hi,

Is there a DOS command in windows 2000 to make a directory equal to todays
date in something like ISO format (YYYYMMDD - e.g. 20050519 for todays
date).

I tried
md "%date%"
but because of the /s in the date format it it made:
Thu 19\05\2005
which doesn't work because I need year first.

I guess maybe I could change the date format then change it back
aftwarwards?

PS: Why does SET /? give you heaps of detail - but in the Windows 2000 help
there is f**k all on set...?

In answer to your last question: It seems you need to take the time to RTFM.

In answer to your main question: It's a straight application of
the set /? and for /? commands.

@echo off
for /F "tokens=2" %%a in ('echo %date%') do set d1=%%a
set d2=%d1:/=%
echo date=%d2%
 
W

wayfarrer

This will make your folder for you from a batch file:

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do md %%C%%A%%B
 
T

Tom Del Rosso

Pegasus (MVP) said:
@echo off
for /F "tokens=2" %%a in ('echo %date%') do set d1=%%a
set d2=%d1:/=%
echo date=%d2%

Why is the command output form as in ('echo %date%') or ('date/t') so often
favored over the simple (%date%) form?
 
P

Pegasus \(MVP\)

Tom Del Rosso said:
Why is the command output form as in ('echo %date%') or ('date/t') so often
favored over the simple (%date%) form?

Whenever possible I use %date%. AFAIK it is not possible
to extract dd/mm/yy by just using %date% - I ***must***
first write it to the screen with an "echo" command. If you
know of a way then please post it!
 
T

Tom Del Rosso

Pegasus (MVP) said:
Whenever possible I use %date%. AFAIK it is not possible
to extract dd/mm/yy by just using %date% - I ***must***
first write it to the screen with an "echo" command. If you
know of a way then please post it!

I'm surprised because I thought it was just as easy. Maybe we have a
miscommunication, but this is what I meant. These are fragments from two of
my batch files.

-----------
set backupdate=%date: =_%
set backupdate=%backupdate:/=-%
-----------

The next one re-orders the year, month, etc, so the variable can go into
names that are sortable. The output of ('time/t') is 12 hour and doesn't
have fractional seconds, but I wanted 24 hour format so (%time%) was
preferable here. The fractional seconds are discarded. I took a "snapshot"
of the date and time simultaneously because it might run around midnight.
(I inserted blank lines after the lines that are split by the newsreader to
make it readable.)

-----------
:Settimestamp
REM set environment variable with 'd-a-t-e_t-i-m-e'
set timesnapshot=%date% %time%
for /f "Tokens=1-4 Delims=/ " %%A in ("%timesnapshot%") do set
dt=%%D-%%B-%%C_%%A

for /f "Tokens=3,4 Delims=: " %%A in ("%timesnapshot%") do set tm=%%A-%%B
REM it is desirable to have 1-digit hours with leading 0 so sorting comes
out right

REM if second character is "-" then the hour has 1 digit
if "%tm:~1,1%"=="-" set tm=0%tm%
set dttm=%dt%_%tm%
goto :eof
 
P

Pegasus \(MVP\)

Tom Del Rosso said:
I'm surprised because I thought it was just as easy. Maybe we have a
miscommunication, but this is what I meant. These are fragments from two of
my batch files.

-----------
set backupdate=%date: =_%
set backupdate=%backupdate:/=-%
-----------

The next one re-orders the year, month, etc, so the variable can go into
names that are sortable. The output of ('time/t') is 12 hour and doesn't
have fractional seconds, but I wanted 24 hour format so (%time%) was
preferable here. The fractional seconds are discarded. I took a "snapshot"
of the date and time simultaneously because it might run around midnight.
(I inserted blank lines after the lines that are split by the newsreader to
make it readable.)

-----------
:Settimestamp
REM set environment variable with 'd-a-t-e_t-i-m-e'
set timesnapshot=%date% %time%
for /f "Tokens=1-4 Delims=/ " %%A in ("%timesnapshot%") do set
dt=%%D-%%B-%%C_%%A

for /f "Tokens=3,4 Delims=: " %%A in ("%timesnapshot%") do set tm=%%A-%%B
REM it is desirable to have 1-digit hours with leading 0 so sorting comes
out right

REM if second character is "-" then the hour has 1 digit
if "%tm:~1,1%"=="-" set tm=0%tm%
set dttm=%dt%_%tm%
goto :eof

Very nice code, and an elegant alternative to my own suggestion.
 
A

adeveloper

Thanks.

RTFM - fair point.
But you still didn't tell me why set /? has much more details than the
windows 2000 help command reference on the SET command. I would expect the
help to be more details than the /? output.
 
P

Pegasus \(MVP\)

adeveloper said:
Thanks.

RTFM - fair point.
But you still didn't tell me why set /? has much more details than the
windows 2000 help command reference on the SET command. I would expect the
help to be more details than the /? output.

Presumably because the people who use the set command
and its many switches feel very comfortable in a Command
Prompt environment. They rarely use the GUI help.
 

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