DOS datetime variable problem?
Greetings. I am new to batch files. I am trying to create a datetime stamp variable in
YYYYMMDD HH:MM:SS.MS format.
If I run the below from the command prompt...
ECHO %date:~-4,4%%date:~-10,2%%date:~-7,2% %time%
it returns the correct value. However, if I do...
SET /a datetime=%date:~-4,4%%date:~-10,2%%date:~-7,2% %time%
ECHO %datetime%
this returns only the date and the HH portion of the time. Does anyone know how to be able to save the date and time as a string variable? Thank you.
Greg
Comments
Try something like
set datetime=%date:~0,3%: %date:~-4,4%-%date:~-7,2%-%date:~4,2%
Change the numbers if you need to - this is for the default US format, Sat 07/10/2010