PC Review


Reply
Thread Tools Rate Thread

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

 
 
adeveloper
Guest
Posts: n/a
 
      19th May 2005
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


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      19th May 2005

"adeveloper" <(E-Mail Removed)> wrote in message
news:d6hi94$4eb$(E-Mail Removed)...
> 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%


 
Reply With Quote
 
wayfarrer
Guest
Posts: n/a
 
      19th May 2005
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

"adeveloper" <(E-Mail Removed)> wrote in message
news:d6hi94$4eb$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Tom Del Rosso
Guest
Posts: n/a
 
      19th May 2005
"Pegasus (MVP)" <(E-Mail Removed)> wrote in message
news:%23CgCH$(E-Mail Removed)...
>
> @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?


--

Reply in group, but if emailing add
2 more zeros and remove the obvious.


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      19th May 2005

"Tom Del Rosso" <(E-Mail Removed)> wrote in message
news:dm7je.230182$(E-Mail Removed)...
> "Pegasus (MVP)" <(E-Mail Removed)> wrote in message
> news:%23CgCH$(E-Mail Removed)...
> >
> > @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?


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!


 
Reply With Quote
 
Tom Del Rosso
Guest
Posts: n/a
 
      20th May 2005
"Pegasus (MVP)" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> 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
-----------

--

Reply in group, but if emailing add
2 more zeros and remove the obvious.


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      20th May 2005

"Tom Del Rosso" <(E-Mail Removed)> wrote in message
news:W3aje.230581$(E-Mail Removed)...
> "Pegasus (MVP)" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >
> > 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
> -----------
>
> --
>
> Reply in group, but if emailing add
> 2 more zeros and remove the obvious.


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


 
Reply With Quote
 
adeveloper
Guest
Posts: n/a
 
      20th May 2005
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.


"Pegasus (MVP)" <(E-Mail Removed)> wrote in message
news:%23CgCH$(E-Mail Removed)...
>
> "adeveloper" <(E-Mail Removed)> wrote in message
> news:d6hi94$4eb$(E-Mail Removed)...
> > 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%
>
>



 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      20th May 2005

"adeveloper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Howw can I make a function return a date in date format Jan Kronsell Microsoft Excel Programming 12 21st Jan 2010 04:24 PM
i have two date fileds Opend date Due date, can i set default on due date so, its always = to open date on my data entry form1 Urgent Mike Saifie Microsoft Access Form Coding 1 9th Mar 2006 01:08 AM
Make date change in excel to current date when opening daily? =?Utf-8?B?amFtaWU=?= Microsoft Excel Misc 3 1st Mar 2006 03:37 PM
Re: Make Directory With Name As Date stat Microsoft Windows 2000 CMD Promt 3 13th Jul 2003 06:19 AM
Make Directory With Name As Date Daniel Key Microsoft Windows 2000 CMD Promt 3 10th Jul 2003 12:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.