Date Format in Batch Script

R

Radhakrishnan

Hi,

Daily i used to check my Files and Directory Structure in
my server for this i will use the Dir /s >filename.

Since i need to keep it in daily basis. so use to execute
the batch file whis have the above given command in that.
once the batch file completed its execution i will go and
change the file name in to this format Day-Date-Month-
Year.txt. i want to know is that possible to do this date
formating also in the batch file it self, if this is
possible please advice me i would like to implement the
same in the script. please send me the mail to
(e-mail address removed). It will be really use full
for me.

Thanks & Regards,

Radhakrishnan. K
([email protected])
 
P

Phil Robyn

Radhakrishnan said:
Hi,

Daily i used to check my Files and Directory Structure in
my server for this i will use the Dir /s >filename.

Since i need to keep it in daily basis. so use to execute
the batch file whis have the above given command in that.
once the batch file completed its execution i will go and
change the file name in to this format Day-Date-Month-
Year.txt. i want to know is that possible to do this date
formating also in the batch file it self, if this is
possible please advice me i would like to implement the
same in the script. please send me the mail to
(e-mail address removed). It will be really use full
for me.

Thanks & Regards,

Radhakrishnan. K
([email protected])

If the format of %date% on your system is DAY MM/DD/YYYY,
then you could use the following; otherwise, adjust the
tokens to accommodate the order of date elements on your
system.

for /f "tokens=2-4 delims=/ " %%a in (
"%date%"
) do set mm=%%a&set dd=%%b&set yyyy=%%c
dir /s > %yyyy%-%mm%-%dd%
 

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