Skip to main content

Posts

Showing posts from April, 2012

Get Current Date Time in SQL Server with GETDATE(), CURRENT_TIMESTAMP and {fn NOW()}

There are three different ways to get the current datetime in SQL SERVER. GETDATE(), CURRENT_TIMESTAMP, and {fn NOW()} GETDATE() and  CURRENT_TIMESTAMP : GETDATE and  CURRENT_TIMESTAMP  are nondeterministic functions. Views and expressions that reference these column cannot be indexed. GETDATE and  CURRENT_TIMESTAMP  can be used to print the current date and time every time we execute the function. {fn Now()} : This is an ODBC canonical function which can be used in T-SQL since the OLE DB provider for SQL Server supports them. {fn Now()} can be used to print the current date and time every time we execute the function. Performance: There is absolutely no difference in using any of them. As they are absolutely same.  If you run following script in Query Analyzer. It will give you same results. If you see execution plan there is no performance difference. It is same for all the three select statement. SELECT GETDATE() GO SELECT CURRENT_TIMESTAMP GO SELECT