Is it possible to format date in command line to specific format? [duplicate]

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?

0

2 Answers

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 

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!

7

You Might Also Like