3

Am trying to format date in cmd windows but it is not coming out nicely.

echo %date% +"%d-%B-%Y". How should I go about it?

Moses
  • 153

2 Answers2

3

You might be interested in the wmic command which can return the local date/time in a locale-independent manner.


@echo off
Title wmic command which can return the local date/time in a locale-independent manner
@for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
echo Today : %today%
set "year=%MyDate:~2,2%"
set "month=%MyDate:~4,2%"
set "day=%MyDate:~6,2%"
echo %day%-%month%-%year%
pause
Hackoo
  • 1,410
-1

I belive this is what you want:

set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
set dateformatted=%month%-%day%-%year%
echo %dateformatted%

Answer from here. Have fun!