SQL SYSDATETIME

The SQL Server SYSDATETIME function is a Date Function, which is used to return the Current Date and Time of the computer on which the Server instance is running as DATETIME2(7). The syntax of the SYSDATETIME Statement is

SYSDATETIME()

SQL Server SYSDATETIME Example

In this example, we are going to show you the SYSDATETIME examples. The SYSDATETIME function returns the datetime2 data type. And the format is: ‘yyyy-mm-dd hh:mm:ss.nnnnnnn’ (you can see that the fractional seconds precision = 7).

SELECT SYSDATETIME() AS [Current_Date]
SYSDATETIME() Current Date and Time

NOTE: This function is similar to the SQL GETDATE(), and the differences are:

  • It returns the fractional seconds precision up to 7, whereas the GETDATE returns up to 3
  • It returns datetime2 as the data type, whereas the GETDATE returns DateTime

Example 1: Get the current system date

In the following query, we use SYSDATETIME() to get the current system date and time. Next, we use SQL CONVERT() to display the DATE part from the current system datetime.

SELECT CONVERT(DATE, SYSDATETIME())
2026-11-04

Example 2: Get the current system time

This time, replace DATE with TIME. The CONVERT() function converts the DATETIME2 to the TIME data type and returns the current system time.

SELECT CONVERT(TIME, SYSDATETIME())
14:36:16.0874547

Using SQL SYSDATETIME() with DATEPART, DATENAME, and DATEADD

Similar to the above, we use SYSDATETIME() to get the current system date and time. Next, we use other built-in DATE and TIME functions to get the day, milliseconds, etc.

In the first three statements, we used the SQL DATEPART to display the Milliseconds, Microseconds, and Nanoseconds from today’s date & time. Next, we used the SQL DATENAME of the SQL Server tutorial to display the weekday name from today’s date & time.

in the last line, we used the SQL DATEADD to display Tomorrow’s date & time

SELECT 'Today' AS 'TODAY', SYSDATETIME() AS [Current_Date];

SELECT 'Milli Seconds' AS 'MILLI', DATEPART(millisecond, SYSDATETIME()) AS [Milli_Seconds]; 
SELECT 'Micro Seconds' AS 'MICRO', DATEPART(microsecond, SYSDATETIME()) AS [Micro_Seconds]; 
SELECT 'Nano Seconds' AS 'NANO', DATEPART(nanosecond, SYSDATETIME()) AS [Nano_Seconds]; 

SELECT 'Day' AS 'DAY', DATENAME(WEEKDAY, SYSDATETIME()) AS [Day_Name]; 

SELECT 'Tomorrow' AS 'DAY', DATEADD(day, 1, SYSDATETIME()) AS [Next_Date];
SQL SYSDATETIME Function 2

Use the SQL SYSDATETIME function on table columns

In this Date Function example, we use the SQL DATEDIFF function to check for Employee details. That includes what year we hired him, how many weeks he associated with our company, etc. Refer to the list of SQL Date functions.

SELECT [FirstName] + ' '+ [LastName] AS [Full Name]
      ,[Occupation]
      ,[YearlyIncome]
      ,[HireDate]
      ,DATEDIFF (year, [HireDate], SYSDATETIME()) AS [YEARS]
      ,DATEDIFF (day, [HireDate], SYSDATETIME()) AS [DAYS]
      ,DATEDIFF (WEEK, [HireDate], SYSDATETIME()) AS [WEEKS]
      ,DATEDIFF (WEEKDAY, [HireDate], SYSDATETIME()) AS [WEEKDAY]
  FROM [Employes]

From the below screenshot, you can observe that we are finding the difference between the Employee Hire date and Today’s system date & time (SYSDATETIME()) using the DATEDIFF function.

TIP: Please refer to the CURRENT_TIMESTAMP and SYSUTCDATETIME functions.

SYSDATETIME Function 3

NOTE: If we have a DATETIME column (record insert date), we can set the DEFAULT to SYSDATETIME(), or we can explicitly mention this function in the INSERT statement. Refer to the SQL INSERT.

INSERT INTO [dbo].[Employee]
([FirstName],[LastName],[Occupation],[YearlyIncome], [HireDate])
VALUES ('Sam', 'Walter', 'Engineer', 120000, SYSDATETIME())
Categories SQL