Get System Date and Time in SQL Server Transact-SQL

Q

How to get system date and time in SQL Server Transact-SQL? I want a list of functions for getting current system date and time.

✍: FYIcenter.com

A

Here is a comparison of all functions that you can use to get the current date and time from the data base server system:

Function              Return type         Precision
-------------------   -----------------   -----------
SYSDATETIME()         DATETIME2(7)        0.0000001 s
SYSDATETIMEOFFSET()   DATETIMEOFFSET(7)   0.0000001 s
SYSUTCDATETIME()      DATETIME2(7)        0.0000001 s
CURRENT_TIMESTAMP     DATETIME            0.00333 s
GETDATE()             DATETIME            0.00333 s
GETUTCDATE()          DATETIME            0.00333 s

Things to remember with selecting the get system date and time functions:

  • CURRENT_TIMESTAMP is like a system variable. You call it without the empty parentheses.
  • The accuracy of times returned by these functions are also depending on the accuracy of the clock of the server system. If the server clock is wrong, you will get wrong time.
  • The precision of times returned by these functions are also depending on the precision of the time function of the server system. If the server time function only supports 0.001-second precision, you will get 0.001-second precision even you call the high precision function SYSDATETIME().

 

Verify Time Precision in SQL Server Transact-SQL

Date/Time Data Type Comparison in SQL Server Transact-SQL

Date/Time Operations and Functions in SQL Server Transact-SQL

⇑⇑ SQL Server Transact-SQL Tutorials

2017-02-25, 1596🔥, 0💬