Very easy to get the date and time, actually:
set Year=
for /f "skip=2" %%x in ('wmic Path Win32_LocalTime get Year^,Month^,Day^,Hour^,Minute^,Second /Format:List') do (
if not defined Year set %%x
)
I'm assuming local time here. If you need UTC, adapt it accordingly.
Your format makes things more complicated. Apologies if I get something wrong here, I'm not familiar with am/pm formats.
if %Hour% LSS 12 (
set ampm=AM
if %Hour%==0 set Hour=12
) else (
set ampm=PM
set /a Hour-=12
)
We need a few leading zeroes:
if %Month% LSS 10 set Month=0%Month%
if %Day% LSS 10 set Day=0%Day%
if %Minute% LSS 10 set Minute=0%Minute%
if %Hour% LSS 10 set Hour=0%Hour%
Then it's time to assemble the parts:
set Timestamp=%Month%-%Day%-%Year% %Hour%:%Minute% %ampm%
(Just a random note: Why on earth would you want that timestamp format?)
You cannot do that in DOS.
If by DOS you mean the Windows Command Processor cmd.exe
then you can get the output of a command with for /f
:
for /f %%x in ('date') do set "today=%%x"
Depending on your requirements this can get a little more complex.
Best Answer
Open a command prompt window. I don't think it requires administrative privileges, but if it says Access Denied after you attempt to change the date/time, close the window and reopen with administrative privileges.
With the command prompt open, type
date
and press enter. It asks you to enter a new date. Do so and press enter again.Now type
time
and press enter. It asks you to enter a new time.If at either of these prompts, you press enter without entering a new date/time, the date/time will not be changed.