How to get mm-dd-yyyy in a DOS batch file?

In the batch file, I need to get the file from the folder with today's date.

The problem is that I cannot get the date command command to return the correct format.

I have this: echo% date: / = -%

But it always comes back, for example: Fri 06-20-2014

What is the right call to return: 06-20-2014

For all found could not be found.

Thank!

+4
source share
2 answers

This works regardless of the regional date / time format:

for /f %%I in ('wmic os get localdatetime ^|find "20"') do set dt=%%I
REM dt format is now YYYYMMDDhhmmss...
set dt=%dt:~4,2%-%dt:~2,2%-%dt:~0,4%
echo %dt%
+8
source
set $date=%date:~4%
set $date=%$date:/=-%
echo %$date%
+7
source

Source: https://habr.com/ru/post/1545422/


All Articles