How To Retrieve The Current Date Time in SQL Server?

There are many in built functions provided by the SQL Server which can be used to fetch the current date time.
The date time that is fetched by these functions would be the date time of the server on which the SQL Server is installed. The time zone also corresponds to the Server On which the SQL Server is installed.

In order to fetch the current date time in SQL server the following Date and Time Functions can be used:

  • {fn NOW()}

Advanced Details:

All the above functions use the windows API GetSystemTimeAsFileTime() to fetch the current data time. The precision for this API is fixed to ~100 Nano seconds.

Date time Functions SYSDATETIME (), SYSDATETIMEOFFSET(), SYSUTCDATETIME() are high precition functions and the functions CURRENT_TIMESTAMP, GETDATE(), GETUTCDATE()are low precision functions.

All the above functions have the same output in the query analyzer as shown in the below image:

datetime functions sql queryanalyzer
datetime functions sql queryanalyzer

This means using any of the above functions has the same performance impact.

Simply speaking, In order to get a high precision date time value then the function SYSDATETIME () can be used and for low precision date time value the function GETDATE() can be used.

Leave a Reply

Your email address will not be published. Required fields are marked *