This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
198} Get how long the system has been up since the last boot?

Using
PowerShell-aided cmd.exe script.
Compare with
item#136.
@echo off & setlocal enableextensions
call :UptimeFromPS uptime_
echo %%uptime_%%=%uptime_%
endlocal & goto :EOF
:: The indentation is essential to avoid incorrect syntax
:: The time separators are escaped
\
:UptimeFromPS
setlocal
for /f "usebackq delims=" %%A in (`powershell -NoLogo -NoProfile -Command ^
"$u=(Get-Date)-(Get-CimInstance Win32_OperatingSystem).LastBootUpTime;"
"$u.ToString('d\.hh\:mm\:ss')"`) do (set "return_=%%A")
endlocal & set "%1=%return_%" & goto :EOF
The output might be e.g.
C:\_M>C:\_D\TEST\UPTIME.CMD
%uptime_%=3.09:04:56
For more PowerShell-aided cmd.exe command-line solutions see
#powershell.

Using ordinary cmd.exe commands gives the last boot time (but not directly the uptime):
@echo off & setlocal enableextensions
for /f "tokens=3,4" %%d in (
'net statistics workstation^|find "Statistics since"') do (
set lastboot=%%d %%e
)
echo/
echo Last booted %lastboot%
endlocal & goto :EOF
The output might be e.g.
C:\_M>C:\_D\TEST\CMSFAQ.CMD
Last booted 20.08.2026 09:37:45