Fetch current date time in SQL Server

Posted on : 28-06-2011 | By : Devi Prasad | In : SQL Date Time Functions, SQL Server Basics



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.

Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.

Your Ad Here

Tags: , , , , , , , , ,