After failing many times before, I have finally found out how to create user-friendly timestamps in batch scripts. For many people this may be yesterday's news, but I am posting it here as a reminder to myself and in hope that it might help someone else.
Windows command shell (sometimes erroneously called DOS prompt) provides
%TIME% environment variables which, unsurprisingly, return current date and time. On the other hand, it is possible to extract a group of characters from any environment variable using following syntax:
VARIABLE is the name of the environment variable,
START is the zero-based index of the first character to be retrieved and
LENGTH is the length of the string to be retrieved. E.g.
%USERNAME:~1,3% would return second, third and fourth letter of the current user's name.
So in order to create a time stamp, we define a temporary environment variable with value defined by parts of
%TIME%. Then we use this variable to create file names. Please note that the exact indices will depend on your time format settings. In a batch file or a script it would look like this:
Output of the batch file is: