CURRENT_TIMESTAMP (T-SQL)

Returns the current date and time. This function is equivalent to GETDATE().

Syntax

CURRENT_TIMESTAMP

Return Types

datetime

Examples
A. Use CURRENT_TIMESTAMP to return the current date and time

    This example returns the value of CURRENT_TIMESTAMP and a text description.

    SELECT 'The current time is: '+ CONVERT(char(30), CURRENT_TIMESTAMP)

      

    Here is the result set:

    ---------------------------------------------------

    The current time is: Feb 24 1998  3:45PM           

      

    (1 row(s) affected)

      

    B. Use CURRENT_TIMESTAMP as a DEFAULT constraint

    This example creates a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint for the sales_date column of a sales row.

    USE pubs

    GO

    CREATE TABLE sales2

    (

     sales_id int IDENTITY(10000, 1) NOT NULL,

     cust_id  int NOT NULL,

     sales_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,

     sales_amt money NOT NULL,

     delivery_date datetime NOT NULL DEFAULT DATEADD(dd, 10, GETDATE())

    )

    GO

    INSERT sales2 (cust_id, sales_amt)

        VALUES (20000, 550)

      

    This query selects all information from the sales2 table.

    USE pubs

    GO

    SELECT *

    FROM sales2

    GO

      

    Here is the result set:

    sales_id    cust_id    sales_date          sales_amt delivery_date              

    ----------- ---------- ------------------- --------- -------------------

    10000       20000      Mar 4 1998 10:06AM  550.00    Mar 14 1998 10:06AM

      

    (1 row(s) affected)

      

    See Also
    ALTER TABLE System Functions
    CREATE TABLE  

      


    (c) 1988-98 Microsoft Corporation. All Rights Reserved.