Windows technique to print timestamps before & after from the command line
On Unix, a quick way to output timestamps is:
But if you try a similar approach at the Windows command prompt, there's a few problems.$ date ; slowcommand ; date Tue Sep 2 12:12:18 MDT 2014 Tue Sep 2 12:12:34 MDT 2014 $
- The command TIME /T outputs the time, but only in HH:MM format.
- The command prompt's builtin magic variable %TIME% outputs HH:MM:SS.ss, but if you try it, the results are unexpected:
C:\>echo %TIME% && SLOWCOMMAND && echo %TIME%The timestamps come out the same, because the command prompt does all variable substitution in a line at once, before executing the first command.
In batch files, this can be mitigated with the setting ENABLEDELAYEDEXPANSION and referring to variables !LIKETHIS! instead of %LIKETHIS%. But that won't work at the command prompt.
C:\>echo %TIME% && SLOWCOMMAND && cmd /c echo %TIME^%Other solutions welcome.