I am trying to write a script that will automatically insert today's date and time into a file name without illegal characters for a filename. I am using the advice and code borrowed from here. http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us
Here is the code I am using in a batch file being run on a Windows Server 2003 STD 32 bit.
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
The problem I am having is the line in the code that is supposed to return the time in 24 hour format is returning the exact same time in 12 hour format every time. This really weird.
C:\Program Files\Windows Resource Kits\Tools>For /F "tokens=1-2 delims=/:" %a in
("0955 AM") do (set mytime=%a%b )
C:\Program Files\Windows Resource Kits\Tools>(set mytime=0955 AM )
C:\Program Files\Windows Resource Kits\Tools>echo 0955 AM
The exact same code run on my Windows 7 box returns the current time in 24 hour format as expected.
Has anyone else heard of or encountered this problem before?