How to create a folder with the current date name in Windows cmd.exe

2

What I already have: %date% is the windows variable that stores the current date. When I use echo %date% the value Tue 07/25/2017 is correctly printed.

But when I try to do mkdir %date% the created folder is Tue 07 because windows does not recognize / as a valid character.

How do I get around this?

    
asked by anonymous 25.07.2017 / 22:18

3 answers

2

You can not add / to the folder name. You should use a date mask ... Usually YYYYMMDD or ANO MES e DIA is used, so it's easy to sort the files by date ...

Here is an example of how to implement ...

set filedatetime=%date% // ou qualquer outra data
set filedatetime=%filedatetime:~6,4%%filedatetime:~3,2%%filedatetime:~0,2%
echo "%filedatetime%" //exemplo da saida... "20170725"

Then you just have to give

mkdir %filedatetime%

Reference

    
25.07.2017 / 22:28
1

Since the requirement is only to show the whole date, try:

mkdir %date:/=%
    
25.07.2017 / 22:25
1

Change the bars by hyphens by adding :/=- after date

mkdir %date:/=-%
    
25.07.2017 / 22:26