Update Option to run a line:
The command wmic OS Get localdatetime /value
returns the string LocalDateTime=20190609123708.733000-180
, using 2 delimiters, =.
, we get 20190609123708
, then we use output substring to compose the layout to create the folder:
%_data:~0,4%_%_data:~4,2%_%_data:~6,2%
Ano:2019 _ Mês:06 _ Dia:09
At bat:
@echo off & for /f "tokens=2delims==." %%i in ('wmic OS Get localdatetime /value ^|findstr /r [0-9]')do set "_data=%%i" & call mkdir %_data:~0,4%_%_data:~4,2%_%_data:~6,2%
On the command line:
for /f "tokens=2delims==." %i in ('wmic OS Get localdatetime /value ^|findstr /r [0-9]')do set "_data=%i" & call mkdir %_data:~0,4%_%_data:~4,2%_%_data:~6,2%
Date format varies according to: region, language and/or settings made by the user
Reference:
Safe way to get Current day Month and year in batch
Parsing Dates in Batch Files & Regional Settings / Locale
To variable %date%
will always display the date in the second format language &
country, or in a format customized/configured by the user, that is to say, nay follows fixed layout/pattern, where we can work from predictive form, and, consequently, manipulate the output string, relying on a fixed/predictable layout
I suggest using the wmic
, where, assuredly, you have a standardized exit and independent of any region, language and/or any settings made by user.
The command:
wmic Path Win32_LocalTime Get Day,Month,Year
Always returns in looping for:
[dia = 29 = %%a] [mês = 4 = %%b] [ano = 2019 = %%c]
After executing the command:
wmic Path Win32_LocalTime Get Day,Month,Year
We have the result:
Day Month Year
29 4 2019
%%a %%b %%c
Script Dir_date.cmd:
@echo off & setlocal enabledelayedexpansion & set "_do=wmic Path Win32_LocalTime Get Day^,Month^,Year"
for /f "tokens=1-3delims= " %%a in ('!_do!^|findstr /r [0-9]')do set "y=%%c" & set "d=0%%a" & set "m=0%%b"
2>nul mkdir !y!!m:~-2!!d:~-2! >nul
Obs.: In Powershell, the layout can be customized with the ToString("yyyyMMdd")
, where the options allow composing in the desired layout just by editing the strings with the ToString
.
Example: yyyy-MM-dd, dd-MM-yyyy, MM-dd-yyyy, MM_dd_yyyy, yyyy_MM_dd, etc..
New-item -Name $(Get-Date).ToString("yyyyMMdd") -ItemType directory
The date format should be Tue 07/25/2017 same, or should only contain day, month and year?
– Artur Trapp
It can be anything that can identify the date type 07-25-2017, 25072017, ...
– Danilo Favato