For SQL Server start time, I use this:
select SQL_Server_Start_Time = min(login_time) from sysprocesses
SQL_Server_Start_Time
------------------------------------------------------
2006-04-07 17:03:23.493
(1 row(s) affected)
For system uptime, I usually get it with the PSINFO utility:
C:\>PSINFO \\MYCOMPUTER
PsInfo v1.73 - Local and remote system information viewer
Copyright (C) 2001-2005 Mark Russinovich
Sysinternals - www.sysinternals.com
System information for \\MYCOMPUTER:
Uptime: 0 days 2 hours 50 minutes 58 seconds
Kernel version: Microsoft Windows 2000, Uniprocessor Free
Product type: Professional
Product version: 5.0
Service pack: 4
Kernel build number: 2195
Registered organization:
Registered owner: Dr. Evil
Install date: 3/18/2002, 5:48:16 PM
Activation status: Not applicable
IE version: 6.0000
System root: C:\WINNT
Processors: 1
Processor speed: 930 MHz
Processor type: Intel Pentium III
Physical memory: 256 MB
Video driver: Radeon DDR
C:\>
You can also get the system start time from the system event log with the PSLOGLIST utility by looking to see when the event log was last started:
C:\>psloglist -id 6005 -n 1
PsLoglist v2.62 - local and remote event log viewer
Copyright (C) 2000-2005 Mark Russinovich
Sysinternals - www.sysinternals.com
System log on \\MYCOMPUTER:
[5986] EventLog
Type: INFORMATION
Computer: MYCOMPUTER
Time: 4/7/2006 5:03:10 PM ID: 6005
The Event log service was started.
Combining the two sources of info:
set nocount on
drop table #t
create table #t (cmdout varchar(500) )
insert into #t
exec master.dbo.xp_cmdshell 'psloglist -id 6005 -n 1'
select
SYSTEM_UP_SINCE =
convert(datetime,substring(cmdout,14,22)),
SQL_SERVER_START_TIME
from
#t
cross join
(select SQL_SERVER_START_TIME = min(login_time)
from sysprocesses ) a
where
cmdout like '% Time: %'
Results:
SYSTEM_UP_SINCE SQL_SERVER_START_TIME
----------------------- -----------------------
2006-04-07 17:03:10.000 2006-04-07 17:03:23.493
CODO ERGO SUM