﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Lars Søe Mikkelsen  / How long has passed since SQL Server service started? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 18:50:25 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Hi ScottThanks for your improvement input - much appreciated :)Best regardsLars MikkelsenJN Data</description><pubDate>Mon, 08 Nov 2010 01:06:40 GMT</pubDate><dc:creator>Lars Søe Mikkelsen</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Very nice!  You can shorten it up a bit though :-)[code="sql"]DECLARE @minutesSinceSQLStarted intSELECT @minutesSinceSQLStarted = DATEDIFF(MINUTE,    -- determines when tempdb was created (done at startup)      (SELECT crdate FROM master.dbo.sysdatabases WHERE name = 'tempdb'), GETDATE())PRINT 'Time since SQL Server service was started: ' +     CONVERT(varchar(4), @minutesSinceSQLStarted / (60*24)) + ' days ' +      CONVERT(varchar(2), @minutesSinceSQLStarted % (60*24) / 60) + ' hours ' +     CONVERT(varchar(2), @minutesSinceSQLStarted % (60*24) % 60) + ' minutes.'  [/code]</description><pubDate>Fri, 05 Nov 2010 15:54:15 GMT</pubDate><dc:creator>scott.pletcher</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Hi Henrik,actually you don't need it, but I agree it would be better practice for SQL Server 2005 as well as SQL Server 2008 to use the sys.databases view which is available from SQL Server 2005 and forward.Do do this while still maintaining the compatibility with SQL Server 2000, you could replace this:[code]-- determines when tempdb was created (done at startup)DECLARE @starttime datetimeSET @starttime = (SELECT crdate FROM sysdatabases WHERE name = 'tempdb' )[/code]With this:[code]-- determines when tempdb was created (done at startup)DECLARE @starttime datetimeDECLARE @sql_version sysnameSET @sql_version = convert(sysname, (SELECT SERVERPROPERTY('Productversion')))IF (@sql_version NOT LIKE '8.%')BEGIN	-- SQL Server 2005 and forward	SET @starttime = (SELECT create_date FROM sys.databases WHERE name = 'tempdb')	ENDELSEBEGIN	-- SQL Server 2000	SET @starttime = (SELECT crdate FROM sysdatabases WHERE name = 'tempdb')END[/code]The premises for this however is that you don't execute it on versions older than SQL Server 2000, but I hope you don't have any of them running anyway :-)Best regardsLars Søe MikkelsenJN Data </description><pubDate>Fri, 05 Nov 2010 05:43:22 GMT</pubDate><dc:creator>Lars Søe Mikkelsen</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Hej Lars,For SQL Server 2008 you need to change line 1 fromSELECT crdate FROM sysdatabases WHERE name = 'tempdb'to SELECT create_date FROM sys.databases WHERE name = 'tempdb'Med venlig hilsenHenrik Staun PoulsenStovi Software</description><pubDate>Fri, 05 Nov 2010 05:11:27 GMT</pubDate><dc:creator>henrik staun poulsen</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Fantastic....</description><pubDate>Tue, 02 Mar 2010 01:39:56 GMT</pubDate><dc:creator>Satnam Singh</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Lars,I didn't know it isn't available in SQL 2005. Nice to know for a project I'm working. Thanks for your solution!RegardsMarco</description><pubDate>Thu, 04 Feb 2010 02:48:45 GMT</pubDate><dc:creator>mchofman</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>[quote][b]mchofman (2/4/2010)[/b][hr]Lars,you can also retrieve the start time from this Dynamic Management ViewSELECT sqlserver_start_time FROM sys.dm_os_sys_info(Requires VIEW SERVER STATE permission on the server)Marco[/quote]Hi MarcoThat's correct for SQL Server 2008. The sqlserver_start_time in sys.dm_os_sys_info was added in SQL Server 2008 and wasn't there in SQL Server 2005.Using the tempdb works for all our current versions :) (yes, we still have SQL Server 2000)Kind regardsLars</description><pubDate>Thu, 04 Feb 2010 02:26:45 GMT</pubDate><dc:creator>Lars Søe Mikkelsen</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Lars,you can also retrieve the start time from this Dynamic Management ViewSELECT sqlserver_start_time FROM sys.dm_os_sys_info(Requires VIEW SERVER STATE permission on the server)Marco</description><pubDate>Thu, 04 Feb 2010 02:15:43 GMT</pubDate><dc:creator>mchofman</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Hi jks-591682To get the start time of the service, you could add this line:[code="sql"]PRINT 'SQL Server was started: ' + CONVERT(char,@starttime)[/code]</description><pubDate>Mon, 18 Jan 2010 01:32:25 GMT</pubDate><dc:creator>Lars Søe Mikkelsen</dc:creator></item><item><title>RE: How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Hi Lars.  Very nice Scripts , if you could supply the startdate, ( SQL Server was started: Dec 15 2009 9:56AM  Time since SQL Server service was started: 33 days 23 hours 17 minutes.)  in the Output -  It will fullfill it. Thanks :-)</description><pubDate>Mon, 18 Jan 2010 01:22:23 GMT</pubDate><dc:creator>jks-591682</dc:creator></item><item><title>How long has passed since SQL Server service started?</title><link>http://www.sqlservercentral.com/Forums/Topic848914-2597-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/GETDATE()/69319/"&gt;How long has passed since SQL Server service started?&lt;/A&gt;[/B]</description><pubDate>Sun, 17 Jan 2010 15:28:35 GMT</pubDate><dc:creator>Lars Søe Mikkelsen</dc:creator></item></channel></rss>