Checking the running time since last SQL-Server instance startup

Below script will query sys.dm_exec_sessions to find out how long the SQL-Server instance is running.

Code:

DECLARE @elapsed_time AS DATETIME, @lr_start_time AS DATETIME SELECT @lr_start_time = (SELECT last_request_start_time FROM sys.dm_exec_sessions WHERE session_id=1) SELECT @elapsed_time = GETDATE()- @lr_start_time SELECT DATEDIFF(day,0,@elapsed_time) AS 'DAYS', DATEPART(hour,@elapsed_time) AS 'HOURS', DATEPART(minute,@elapsed_time) AS 'MINUTES', DATEPART(second,@elapsed_time) AS 'SECONDS', DATEPART(millisecond,@elapsed_time) AS 'MILLISECONDS'

And the result is:

DAYS HOURS MINUTES SECONDS MILLISECONDS ----------- ----------- ----------- ----------- ------------ 41 19 9 17 297

CU
tosc

No feedback yet
Leave a comment

Your email address will not be revealed on this site.
PoorExcellent
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)
Trackback address for this post

http://www.insidesql.org/blogs/htsrv/trackback.php?tb_id=135