This does not work:
echo %DATE% %TIME% & timeout 5 & echo %DATE% %TIME%
You'll notice the first and the second values are identical.
You can wrap the command in a quoted string, enable delayed variable expansion, and use ! so the variable expands at execution time rather than when the line is parsed.
cmd /V:ON /C "echo !DATE! !TIME! & timeout 5 & echo !DATE! !TIME!"
Wed 11/19/2025 0:03:00.45
Waiting for 0 seconds, press a key to continue ...
Wed 11/19/2025 0:03:05.19
cmd /?/C Carries out the command specified by string and then terminate
/V:ON Enable delayed environment variable expansion using ! as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
cmd /V:ON, this won't work.
Use net time instead.
For example, either of the following:
net time \\%userdomain% & timeout 5 & net time \\%userdomain%
or
net time %logonserver% & timeout 5 & net time %logonserver%
produce the following output:
Current time at \\<PCNAME> is 11/18/2025 8:34:30 PM
The command completed successfully.
Waiting for <5... 0> seconds, press a key to continue ...
Current time at \\<PCNAME>is 11/18/2025 8:34:35 PM
The command completed successfully.
You can also use the environment variables \\%USERDOMAIN_ROAMINGPROFILE% and \\%USERDOMAIN%. Note that %logonserver% includes the Windows backslashes of the UNC path.
net time \\%userdomain% I get The service has not been started. More help is available by typing NET HELPMSG 2184. What works are net time \\%userDNSdomain% or net time /domain:%userdomain% or simply net time /domain (also net time /rtsdomain, but this takes forever)
You'll notice the first and the second values are identical.
Of course, as variables in cmd are expanded when the command is parsed. There's EnableDelayedExpansion option that you can play with, but I don't think it's an optimal way of measuring command execution times anyways, too much repetitive typing/copying.
Instead I'd recommend using a prompt modifier like Oh My Posh that can automatically output execution time of last command on the fly with execution time segment.
As Destroy mentioned, variables like %TIME% are expanded into literal values when the script/command is initially parsed, and unless they are modified in the script, the same literal value will be used both times the variable is evaluated, so what you are really executing is
echo "Tue 11/18/2025" "16:42:51.15" & timeout 5 & echo "Tue 11/18/2025" "16:42:51.15"
if you want the %TIME% to reference the actual current time on the system, you must "delay variable expansion" until the variable is used. This is generally achieved by setting setlocal enabledelayedexpansion prior to evaluating the variable, and "endlocal" when you are done. Also note that for delayed evaluation to work properly you must reference the variable with !varname!instead of %varname% and is only supported in batch scripts.
This works when executed in a batch file:
setlocal enabledelayedexpansion
echo !DATE! !TIME! & timeout 5 & echo !DATE! !TIME!
endlocal
Presumably you are asking how to gather execution time metrics because you are working on an existing CMD batch-based product, but if you have the option, consider another shell to target. Powershell has shipped by default on every (even close to) currently supported version of windows, so there is broad compatibility for powershell scripts across windows devices.
(Measure-Command {timeout 5}).TotalSeconds. Or .TotalMilliseconds for better resolution.
Set your environment as so:
set prompt=$T$H$H$H$H$H$H$S%computername%\%username%$S$M$P$+$G
(remove all $H for hundredths of seconds or use fewer $H to reveal seconds set prompt=$T$H$H$H$S%computername%\%username%$S$M$P$+$G)
precede your command with an echo %time% as in echo %time% & (your command)
You will see who ran the command on which computer, when it started and when it finished.
Source: GitHub Gist Prompt.txt
9:29 MyPC-11(Admin) C:\Users\me>set prompt=$T$S%computername%\%username%$S$M$P$+$G
9:30:13.05 MyPC-11\me C:\Users\me>echo %time% & ping -n 12 -w 2500 example.com
9:31:57.25
Pinging example.com [2600:1408:ec00:36::2738:7d2a] with 32 bytes of data:
Reply from 2600:1408:ec00:36::2738:7d2a: time=46ms
---8<--- cut
Reply from 2600:1408:ec00:36::2738:7d2a: time=66ms
Ping statistics for 2600:1408:ec00:36::2738:7d2a:
Packets: Sent = 12, Received = 12, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 46ms, Maximum = 71ms, Average = 56ms
9:32:08.57 MyPC-11\me C:\Users\me>
In a command line:
echo %DATE% %TIME% & timeout 1 & call echo ^%DATE^% ^%TIME^%
In a script:
echo %DATE% %TIME% & timeout 1 & call echo %%DATE%% %%TIME%%
A solution that calculates how long the command ran, using set /A , substring extraction with ~ and mitigation against leading space in the number of hours.
set "START=!TIME!" & timeout 5 > nul & set "END=!TIME!"
set /A DURATION=(1!END:~0,2!-1!START:~0,2!)*3600 + (!END:~3,2!-!START:~3,2!)*60 + (!END:~6,2!-!START:~6,2!)
echo Command took !DURATION! seconds
Either run inside an interactive cmd /V:ON session or behind setlocal enabledelayedexpansion inside a .bat file.
It assumes the command doesn't run over midnight, if that's a concern add if !DURATION! LSS 0 set /A DURATION_S+=86400.
date /t & time /tas I'm quite sure I've done that in the past successfully in batch scripts