How do you get the system time from within a batch file?



orksecurity7 years ago
Assuming you're on a relatively recent version of Windows and Command Extensions are turned on (which they usually are), the %TIME% variable will return this.

Running "HELP SET"  or "SET /?" from the command line (without the quotes, of course) will tell you more about the other variables and expressions supported by the batch language. That works for the other .bat/.cmd operations too.

I believe there are instructables which describe more of the tricks of working with command files in Windows -- not to mention whole websites dedicated to useful little idioms. A bit of searching should find all of these.
There are two ways to view the time:

1.
@echo %time%
pause>nul

2.
setlocal enabledelayedexpansion & time /T
pause>nul

Both are viable options.
account3r27 years ago
Thats an easy one. Just type %time% or echo %time%. that should work. always works for me. and you can get the date. same syntax. %date% or echo %date%.