The date and time in DOS Scripting have the following two basic commands for retrieving the date and time of the system.
This command gets the system date.
@echo off echo %DATE%
The current date will be displayed in the command prompt. For example,
This command sets or displays the time.
@echo off echo %TIME%
The current system time will be displayed. For example,
Following are some implementations which can be used to get the date and time in different formats.
@echo off echo/Today is: %year%-%month%-%day% goto :EOF setlocal ENABLEEXTENSIONS set t = 2&if "%date%z" LSS "A" set t = 1 for /f "skip=1 tokens = 2-4 delims = (-)" %%a in ('echo/^|date') do ( for /f "tokens = %t%-4 delims=.-/ " %%d in ('date/t') do ( set %%a=%%d&set %%b=%%e&set %%c=%%f)) endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
The above command produces the following output.
Today is: 2015-12-30