Change date and time format via command prompt
Asked Answered
K

4

5

I was just wondering, in Windows 7 and above, is it possible to change the way dates and times are displayed via the command prompt? Yes, I'm in the U.S. but I like doing things the European way:

(In Clock/Language/Region)

Short Date: Set as "d/M/yyyy"

Long Date: Set as "dddd, d MMMM yyyy"

Short Time: Set as "HH:mm"

Long Time: Set as "HH:mm:ss"

Krak answered 19/4, 2016 at 18:36 Comment(2)
yes, once your system is set by control panel, command prompt will show dates as you defined. And yes, 100% offtopic, and my comment is useless too, you're right.Gownsman
@Marc B - Wrong-o. I am writing a batch file to automate backup. It creates directories that include the date, and I need to make sure the date is in a format that does not include slashes. Hence the need to change the date format automatically with a command. Very much a programming question.Adowa
P
10

Yes, it's possible e.g. using reg add command.
Check the HKEY_CURRENT_USER\Control Panel\International registry key:

reg query "HKCU\Control Panel\International"

For instance, query Short Time format:

reg query "HKCU\Control Panel\International" /V sShortTime

and set it to desired value:

reg add "HKCU\Control Panel\International" /V sShortTime /T REG_SZ /D HH:mm /F

If value name or data contains spaces, use double quotes (surrounding double quotes would not be written to registry):

reg add "HKCU\Control Panel\International" /V sShortTime /T REG_SZ /D "HH:mm" /F

A word of warning: Changing this registry value changes the settings in the user's profile, so it may have side effects in other areas. For example the way the clock is displayed in the task bar. And maybe it breaks other scripts that expect another time/date format.

So be careful when using this trick in something which you give to others!

Percussion answered 19/4, 2016 at 21:10 Comment(0)
F
2

reg add "HKCU\Control Panel\International" /V sShortTime /T REG_SZ /D hh:mm:tt /F

Filide answered 1/12, 2020 at 15:29 Comment(0)
C
0

X:>echo %date:~10,4%%date:~4,2%%date:~7,2% 20181110

Caller answered 10/11, 2018 at 22:59 Comment(2)
default %date% results in textual date format like : X:/echo %date% Sat 11/10/2018 we can format to get yyyymmdd using the date cmd : X:\>echo %date:~10,4%%date:~4,2%%date:~7,2% 20181110Caller
how to get the day of the week? can you update your answer to include an example for day of week?Iong
E
-1

try to use this - to include the weekday

C:\Users>echo %date:~10,4%%date:~4,2%%date:~7,2%%date:~0,3%

20240326Tue

C:\Users>echo %date:~0,3%

Tue

C:\Users>

Executor answered 26/3, 2024 at 8:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.