Home > SQLServer, SQLServer 2005, SQLServer 2008, SQLServer 2008 R2 > SQL Server has been running for …

SQL Server has been running for …

Recently on one of our production servers, which is a two-node Active/Passive cluster.  A failover had occurred. I wanted to find the exact time when this happened. You can get this information from SQL Server Log.

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.

You can check the creation time using:

SELECT create_date

FROM   sys.databases

WHERE  name = 'tempdb'


You can also format the output using:



       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'


This returns below on my local system:




Hope This Helps!


  1. Josh
    17.07.2011 07:35 | #1

    Thanks Vishal, that’s a really handy script. Personally I used to delve into the Event Viewer but your script means I don’t have to leave SQL Management Studio.

    Thanks ?

  1. No trackbacks yet.