What is the simplest way to find out how long a computer is turned on Windows?
13 Answers
there is great command line tool from Microsoft uptime.exe:
good thing with this tool is it works really fast.
Uptime [server] [/s ] [/a] [/d:mm/dd/yyyy | /p:n] [/heartbeat] [/? | /help]
server Name or IP address of remote server to process.
/s Display key system events and statistics.
/a Display application failure events (assumes /s).
/d: Only calculate for events after mm/dd/yyyy.
/p: Only calculate for events in the previous n days.
/heartbeat Turn on/off the system's heartbeat
/? Basic usage.
/help Additional usage information.
- 2,448
Open the command prompt and type:
net stats srv | find "Statistics"
Example output:
>net stats srv | find "Statistics"
Server Statistics for \\4IFS-SANDER
Statistics since 22/07/2009 10:14:14
Source (MS KB).
Edit: Actually this will tell you the date and time when the pc was up from, not the duration.
- 331
- 3,353
On Windows 7 / Windows Server 2008 and above, this information is displayed in task manager under the "Performance tab".
This can be quicker then using the command line and works in cases where you might have WMI issues preventing you from running systeminfo.
If you need to find this remotely, you could also run
systeminfo /s SERVERNAME | find "Time:"
from the command line.
- 320
Following command gives last reboot time for a remote system:
systeminfo /s server_name | find "System Boot Time"
- 331
- 61
Yet another way:
C:\>wmic path Win32_OperatingSystem get LastBootUpTime
LastBootUpTime
20200908203723.500000+120
- 3,168
In windows 10, this is located in Task manager > Expand More Details Chevron > Performance > CPU > At the bottom, Up time.
- 9,176
Using SYSTEMINFO with PowerShell
For those who like using PowerShell, you can use the answer(s) above and wrap systeminfo in a PowerShell function to get a DateTime result for when the server last booted:
function Get-ComputerBootTime {
param($ComputerName = (hostname))
$SystemInfo = & systeminfo /s $ComputerName | Select-String "System Boot Time")
if($SystemInfo -match "[\d/]+,\s+\S+"){
return (Get-Date $matches[0])
}
}
And then call the function, for example:
[PS]> $BootTime = Get-ComputerUptime -ComputerName MYSERVER
To get the Uptime for the server, you compare with the current time:
[PS]> $UpTime = (Get-Date) - $BootTime
This is a TimeSpan, which includes properties such as TotalDays:
[PS]> $UpTime.TotalDays
14.1827364
- 331
Sometimes the uptime is dificult and user is not logged out and the two prety much coincide so I use this command to display the LOGON TIME
query USER
or shorter even:
quser
which prints something like:
C:\Users\eflorinescu>query USER
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
>eflorinescu console 2 Active 2+23:44 5/7/2018 8:25 AM
also even better using PowerShell
Get-ComputerInfo | select-object oslastbootuptime
- 3,186
Anyone wanting the unix time (seconds since the epoch) that are using cygwin can try this:
date +%s -d "$(wmic path Win32_OperatingSystem get LastBootUpTime | grep -E '^[0-9]' | awk '{print substr($1,1,4) "-" substr($1,5,2) "-" substr($1,7,2) " " substr($1,9,2) ":" substr($1,11,2) ":" substr($1,13,2);}')"
- 2,323
In PowerShell either of the following commands will work
Get-WmiObject win32_operatingsystem |% {$_.ConverttoDateTime($_.lastbootuptime)}
(Get-CimInstance -ClassName win32_operatingsystem).lastbootuptime
Get-CimInstance is both shorter and more future proof, because Get-WmiObject and wmic have been both deprecated
You can also run (Get-WmiObject win32_operatingsystem).lastbootuptime but the output is less readable because it's a raw time string
- 30,396
- 15
- 136
- 260
In PowerShell:
$LastBoot = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
$Uptime = (Get-Date) - $LastBoot
Write-Output "System Uptime: $Uptime"
Example output:
System Uptime: 6.08:45:53.8690764
Tested with PowerShell 5.1.26100.2161 on Windows 11 24H2 Pro.
- 24,246
- 64
- 231
- 400

