SQL Server SYSDATETIME Function

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

Summary: in this tutorial, you will learn how to use the SYSDATETIME() function to get the current system date and time.

SQL Server SYSDATETIME() function #

The SYSDATETIME() function returns a value of DATETIME2 that represents the current system date and time of the server on which the SQL Server instance is running.

The SYSDATETIME() function accepts no parameter:

SYSDATETIME()

Here is the output:

Result
---------------------------
2019-05-02 22:22:33.3975855

(1 row affected)

Note that the SYSDATETIME() function has more fractional seconds precision than the GETDATE() function.

The SYSDATETIME() is a nondeterministic function, therefore, views and columns that have expressions reference this function cannot be indexed.

SQL Server SYSDATETIME() function examples #

Let’s take some example of using the SYSDATETIME() function.

A) Returning the current system date example #

This example uses the CONVERT() function to convert the result of the SYSDATETIME() function to the current date:

SELECT 
    CONVERT(DATE, SYSDATETIME());

Here is the result:

Result
----------
2019-05-02

(1 row affected)

B) Returning the current system time #

The following example converts the result of the SYSDATETIME() function to the current time:

SELECT 
    CONVERT(TIME, SYSDATETIME()) Result;

The output is as follows:

Result
----------------
22:32:07.2066595

(1 row affected)

In this tutorial, you have learned how to use the SQL Server SYSDATETIME() function to get the current system date and time.

Was this tutorial helpful?