
The change to one Registry value for doing this is instantaneous temporary and trivial it only lasts a few milliseconds before it is immediately reverted back.ĭouble-click this batch file for an instant demo, Command Prompt window will pop up and display your timestamp. I also used that clever registry trick described by "jph" previously which IMHO is the simplest way of getting 100% consistent formatting of the date to "yyyy_MM_dd" on any Windows system new or old. This batch script will do exactly what the O.P. Reg copy "HKCU\Control Panel\International-Temp" "HKCU\Control Panel\International" /f Reg add "HKCU\Control Panel\International" /v sShortDate /d "yyMMdd" reg query "HKCU\Control Panel\International" /v sShortDate reg copy "HKCU\Control Panel\International" "HKCU\Control Panel\International-Temp" /f
#Set date how to#
This is just an example, but I think you will see how to modify for other date and/or time formats, etc. Yes, it introduces some other issues, but for my purposes I found this to be the easiest, clearest, most portable solution for creating a datestamp in.

There are also batch tricks using the CMOS clock in a pretty raw way, but that is tooo close to bare wires for most people, and also not always the preferred place to retrieve the date/time.īelow is a solution that avoids the above problems. You can also use some external program that will return a date slug in your preferred format, but that has disadvantages of needing to distribute the utility program with your script/batch.

This could be determined, but by the time you do all the stressing and parsing, you will still end up with some situation where there is an unexpected format used, and more tweaks will be be necessary. As has been noted, parsing the date and time is only useful if you know the format being used by the current user (for example, MM/dd/yy or dd-MM-yyyy just to name two).
