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.

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