How to change the date format of today's date in Command prompt
I am trying to fetch the current date using %date%
but i want to format the date as yyyy-mm-dd
.
Asked
Active
Viewed 1,042 times
2 Answers
0
To get the formatting you want, you need to parse the output.
for /F "tokens=2-4 delims=/ " %i in ('date /t') do echo %k-%i-%j
![](../../users/profiles/2249641.webp)
Andrew
- 678
- 4
- 8
-
I'd strongly advise against this, as the code will stop working when your regional settings change. – Joey Oct 29 '14 at 13:25
-
I've used it without a problem for about a two decades now, so I'm not too worried ;-) – Andrew Oct 29 '14 at 13:32
-
That's fine, but bear in mind that people finding this question might try building a batch file that has to run robustly on customer machines where you have no control over those things. Parsing output also can break down with certain locales that include non-ASCII letters in their date format. – Joey Oct 29 '14 at 14:03
0
If you are comfortable using date.exe (part of UnxUtils) there is a related answer here https://stackoverflow.com/a/1951681/422842