How to Programmatically Identify When Your SQL Server Was Last Started | Database Journal

How to Programmatically Identify When Your SQL Server Was Last Started

Written By
Gregory Larsen
Gregory Larsen
Apr 2, 2018
1 minute read

Where do you go to find the last time SQL Server was started?  I’m guessing you might have gone to the ERRORLOG file and reviewed it to determine when SQL Server started.  That method will work.  But what if you programmatically want to script a way to identify when SQL Server was last started.  How would you do that?

There is a simple TSQL way to programmatically identify the last time SQL Server was started.  Here is the code to accomplish this:

SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1;

See all articles by Greg Larsen

Gregory Larsen

Gregory A. Larsen is a DBA at Washington State Department of Health (DOH). Greg is responsible for maintaining SQL Server and other database management software. Greg works with customers and developers to design and implement database changes, and solve database/application related problems. Greg builds homegrown solutions to simplify and streamline common database management tasks, such as capacity management.

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.