• this is what i've used for quite a long time:

    I wanted both server uptime and the SQLService uptime.

    i made a simple stored proc, sp_help_uptime and put it in master, that returns results form a dmv:

    --Results:

    ServerRestartTime ServiceRestartTime ServiceUpTimeInDays ServerUpTimeInDays

    2016-10-15 00:20:34.153 2016-11-11 10:15:24.023 7 34

    the proc:

    IF OBJECT_ID('[dbo].[sp_help_uptime]') IS NOT NULL

    DROP PROCEDURE [dbo].[sp_help_uptime]

    GO

    CREATE PROCEDURE sp_help_uptime

    AS

    select

    DATEADD(second, -1 * ( ms_ticks / 1000),getdate()) as ServerRestartTime,

    i.sqlserver_start_time As ServiceRestartTime,

    DATEDIFF(dd,i.sqlserver_start_time,GETDATE()) AS ServiceUpTimeInDays,

    DATEDIFF(dd,DATEADD(second, -1 * ( ms_ticks / 1000),getdate()),GETDATE()) AS ServerUpTimeInDays

    from sys.dm_os_sys_info i;

    GO

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!