Labels

Tuesday, May 31, 2011

How to check on how long the SQL server is running for ?

One way is to check the SQL Server Logs and the other way and Another quick way is to check the creation time of  “tempdb” database. This will be same as SQL Server Service start time since “tempdb” is recreated each time SQL Server starts.

SELECT create_date
FROM   sys.databases
WHERE  name = ‘tempdb’

OR in a formatted way:

SELECT (DATEDIFF(DAY, create_date, GETDATE()))
       AS [Days],
       ((DATEDIFF(MINUTE, create_date, GETDATE())/60)%24)
       AS [Hours],
       DATEDIFF(MINUTE, create_date, GETDATE())%60
       AS [Minutes]
FROM   sys.databases
WHERE  name = ‘tempdb’

No comments:

Post a Comment