Search code examples
t-sqlinstallationserver

SQL Server Create Date From TSQL


Basically, I am looking for a way to pull the date that the SQL instance was created, using TSQL, ie a CreateDate for the server itself. I could find nothing in the docs or the site. I know I can go scrolling through the system to find a date in the file system, but thought that their might be a way to do it as easily as I can for sys.objects. I thought that maybe I could use a CreateDate off of a table in master or msdb, but that seems to be the date that MS created those. I am running 2019.

Any suggestion would be helpful. Thanks.


Solution

  • Here are several options you can use

    /*********** Retrieve SQL Server Installation Date Time ************/
    
    SELECT 
    @@SERVERNAME AS Server_Name, 
    create_date AS SQL_Server_Install_Date
    FROM sys.server_principals WITH (NOLOCK)
    WHERE name = N'NT AUTHORITY\SYSTEM' OR name = N'NT AUTHORITY\NETWORK SERVICE';
    GO
    
    SELECT
    @@SERVERNAME AS [Server Name],  
    createdate AS SQL_Server_Install_Date
    FROM    sys.syslogins 
    WHERE name = N'NT AUTHORITY\SYSTEM' OR name = N'NT AUTHORITY\NETWORK SERVICE';
    GO
    
    SELECT create_date
    FROM sys.server_principals
    WHERE sid = 0x010100000000000512000000
    GO
    
    -->> Check the setup\installation logs
    
    SELECT createdate
    FROM sys.syslogins
    WHERE name='sa'
    GO