5981Views3Replies

Author Options:

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


3 Replies

orksecurity (author)2010-04-20

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.

Prof. Pickle (author)2012-12-15

There are two ways to view the time:

1.
@echo %time%
pause>nul

2.
setlocal enabledelayedexpansion & time /T
pause>nul

Both are viable options.

account3r2 (author)2010-04-24

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%.