Technical Article

SQL Server Uptime

,

Copy the code, paste in queery analyzer or can be executed from command prompt using SQLCMD or OSQL

---SQL Server Uptime calculation
---------------------------------------------------------------------------------------------
SET NOCOUNT ON
DECLARE @db_cr_date DATETIME, 
@hour int, 
@minut int,
@days int 

SELECT @db_cr_date=crdate FROM 
    master.sys.sysdatabases 
        WHERE NAME='tempdb'

SET @minut = DATEDIFF (mi,@db_cr_date,GETDATE())
SET @days= @minut/1440
SET @hour = (@minut/60) - (@days * 24)
SET @minut= @minut - ( (@hour + (@days*24)) * 60)

Select @@SERVERNAME 
        +' is restarted on '
        + CAST(@db_cr_date as varchar(30)) 
        + ' Server is up and running since last :' 
        + ltrim(str(@days)) +' Days,'
        + ltrim(str(@hour)) +' Hours, '
        + ltrim(str(@minut)) + ' Minuts ' as [Total uptime]
---------------------------------------------------------------------------------------------

Rate

2.8 (5)

You rated this post out of 5. Change rating

Share

Share

Rate

2.8 (5)

You rated this post out of 5. Change rating