You would think that creating a timestamp for a filename (e.g., 20080208-1117.log) would be an easy thing to do since one of the most common things to do with batch commands is automating copy, create and rename file tasks.
I have tried all manner of scripts and third party solutions to attempt to generate a reliable timestamp for labelling files. Here is a fairly simple batch command solution to the problem. It takes the DOS date and time functions and splits the component parts into substrings.
rem Timestamp Generator
rem Parse the date (e.g., Fri 02/08/2008)
rem Parse the time (e.g., 11:17:13.49)
if %cur_hh% lss 10 (set cur_hh=0%time:~1,1%)
rem Set the timestamp format
rem Do something with it
echo Timestamp: %timestamp%
rem Clear the environment variables
The caveat is that it depends on the format of the date and time on your computer which are defined by the regional settings in the Control Panel. If the substrings don’t have the required information in them you may need to tweak the substring positions to suit your date and time settings.