It can be very useful to pull the date and time from the system and put it into variables. Once the date and time are in variables, they can be used to build filenames for log file, etc
First off, make sure the Regional Settings are set to the following:
The following script will pull the numerical date and time into variables.
REM ***************************************************************************
REM time variables
set month=%date:~4,2%
set day=%date:~7,2%
set year=%date:~10,4%
for /f "tokens=5-7 delims=:. " %%a in (
'echo/^|time^|find "current"'
) do set hour=%%a&set minute=%%b&set second=%%c
ECHO YEAR:%YEAR%
ECHO MONTH:%MONTH%
ECHO DAY:%DAY%
ECHO HOUR:%HOUR%
ECHO MINUTE:%MINUTE%
ECHO SECOND:%SECOND%
Now that you've got the date and time in variables, building a file name that contains the date and time is a snap.
SET logfile=%year%-%month%-%day% %hour%-%minute%-%second%.log