DOS FAQ / DOS Operation Problems

Question:

Using the Date/Time in a batch file.

Answer:

Set your batch file or program to redirect envtime.exe's output to a file with an extension of ".bat". Then you must run the new batch file just before you need the time/date. The time and date will then be set to variables which you can insert into any batch file. Just run ENVTIME without any parameters to see what the variables will be. The example batch file below will simply echo the date and time to the screen.
@ECHO OFF
ENVTIME > TIME.BAT
CALL TIME.BAT
ECHO.
ECHO %HOUR%:%MIN%  %DOW% %MON% - %DOM% - %YR%
DEL TIME.BAT