Home > Functions and DMVs, SQL Queries, SQL Server, Stored Procedures, T-SQL > Functions to get the current system datetime in SQL Server

Functions to get the current system datetime in SQL Server

There are different ways of fetching the current time from the sql server. Sql server 2005 provides 3 different functions to fetch the datetime value.

  • Getdate()
  • Current_TimeStamp
  • {fn NOW()}

All these functions are non-deterministic . They all return the same values when executed.

In addition to these functions SQL server 2008 Provides an additional function “SYSDATETIMEOFFSET()”. This function provides the current time offset with GMT.

a sample execution is as below.



SELECT
CURRENT_TIMESTAMP as [CURRENT_TIMESTAMP] , GETDATE() as [GETDATE], {fn NOW()} as [FN]

 
Result: 

CURRENT_TIMESTAMP        GETDATE                 FN
2010-01-25 14:40:10.067 2010-01-25 14:40:10.067 2010-01-25 14:40:10.067

In the above example you can see that the results are same irrespective of the functions. The performance are not different either.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: