SQL THOUGHTS– How to get Current Date Time in SQL Server





Retrieve Current date time


There are four different ways to retrieve the current datetime in SQL SERVER.

  • GETDATE()
  • CURRENT_TIMESTAMP
  • GETUTCDATE
  • {fn NOW()}


  • SCREEN SHOT



    GETDATE()


    GETDATE() is a SQL Server-specific function inherited from the original Sybase code on which SQL Server is based.
    Returns the date and time of the computer on which the instance of SQL Server is running. The time zone offset is not included.



    CURRENT_TIMESTAMP


    CURRENT_TIMESTAMPGETDATE is standard ANSI SQL.Both shows exactly same result however,using an ANSI Standard function is possibly a good thing to do, makes things less DB specific i.e the SQL is portable.



    GETUTCDATE


    GETUTCDATE returns UTC time (Coordinated Universal Time).


    {fn NOW()}


    {fn NOW()} is an ODBC canonical function which can be used in T-SQL

    HappyCoding ! 😉

    Advertisements

    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 )

    Google+ photo

    You are commenting using your Google+ 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 )

    Connecting to %s

    %d bloggers like this: