5.6K
When echo %DATE, by default you get dd/mm/yyyy. There is no built in formatting parameter that you can use, so you cannot change the date format unless you rearrange the output characters around.
Some of the links on this page are affiliate links. I receive a commission (at no extra cost to you) if you make a purchase after clicking on one of these affiliate links. This helps support the free content for the community on this website. Please read our Affiliate Link Policy for more information.
For example to get yyyy-mm-dd as output, you can do this.
set Today=%Date:~6,4%_%Date:~3,2%_%Date:~0,2%
It basically means.
SET Today=%Date:~6,4%-%Date:~3,2%-%Date:~0,2% ^^ ^ ^ ^ || | | | Year| Dash Month Day | Number of chars
Of course the format depends on your local region settings, check %DATE% before you change numbers.
3 comments
My comment a couple of hours ago needs correcting. I had nothing to do with the upgrade – it was caused by running a batch program as an “administrator” from my “standard” account. The Admin account had default “Regional” settings. Once the date was set to the same format in both accounts, the date command began working again.
A regional setting of 19-12-20 creates a date 191220 from this command:
set Date=%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%
Here’s a strange one. Before upgrading to Windows 1909 this command produced 191220:
set Date=%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%
Since upgrading, a BAT with the exact same command produces 209-2-20.
My date setting is yy-mm-dd.P
How to change date format with dd/MM/yyyy?