4

In a batch file I need to get a file from a folder that has today's date.

The problem is I can't get the batch date command to return the proper format.

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

But that always returns for example: Fri 06-20-2014

What's the proper call for just returning: 06-20-2014

Looked all over can't find.

Thanks!

user167908
  • 977
  • 2
  • 9
  • 11
  • 1
    possible duplicate of [How to get current datetime on Windows command line, in a suitable format for using in a filename?](http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us) – npocmaka Jun 20 '14 at 19:51

2 Answers2

10

This works independent of 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:~6,2%-%dt:~0,4%
echo %dt%
Stephan
  • 53,940
  • 10
  • 58
  • 91
8
set "$date=%date:~4%"
set "$date=%$date:/=-%"
echo %$date%
SachaDee
  • 9,245
  • 3
  • 23
  • 33