CURRENT_TIMESTAMP (Transact-SQL)CURRENT_TIMESTAMP (Transact-SQL)

適用於: 是SQL Server (從 2008 開始) 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server (starting with 2008) yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

此函式將目前資料庫的系統時間戳記以 datetime 值傳回 (不含資料庫時區位移)。This function returns the current database system timestamp as a datetime value, without the database time zone offset. CURRENT_TIMESTAMP 會從執行 SQL ServerSQL Server 執行個體之電腦的作業系統衍生這個值。CURRENT_TIMESTAMP derives this value from the operating system of the computer on which the instance of SQL ServerSQL Server runs.

注意

SYSDATETIMESYSUTCDATEGETDATEGETUTCDATE 具有更高的精確度,以小數秒數有效位數來度量。SYSDATETIME and SYSUTCDATE have more precision, as measured by fractional seconds precision, than GETDATE and GETUTCDATE. SYSDATETIMEOFFSET 函式包含系統時區位移。The SYSDATETIMEOFFSET function includes the system time zone offset. 您可以將 SYSDATETIMESYSUTCDATESYSDATETIMEOFFSET 指派給任何日期和時間類型的變數。You can assign SYSDATETIME, SYSUTCDATE, and SYSDATETIMEOFFSET to a variable of any of the date and time types.

這個函式是相當於 GETDATE 的 ANSI SQL。This function is the ANSI SQL equivalent to GETDATE.

如需所有 Transact-SQLTransact-SQL 日期和時間資料類型與函式的概觀,請參閱日期和時間資料類型與函式See Date and Time Data Types and Functions for an overview of all the Transact-SQLTransact-SQL date and time data types and functions.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

CURRENT_TIMESTAMP  

引數Arguments

這個函數沒有引數。This function takes no arguments.

傳回類型Return Type

datetimedatetime

RemarksRemarks

只要是 Transact-SQLTransact-SQL 陳述式可以參考 datetime 運算式的任何位置,它們就可以參考 CURRENT_TIMESTAMPTransact-SQLTransact-SQL statements can refer to CURRENT_TIMESTAMP, anywhere they can refer to a datetime expression.

CURRENT_TIMESTAMP 是非決定性函數。CURRENT_TIMESTAMP is a nondeterministic function. 參考這個資料行的檢視和運算式,是無法編製索引的。Views and expressions that reference this column cannot be indexed.

範例Examples

這些範例會使用六個可傳回目前日期和時間值的 SQL ServerSQL Server 系統函數來傳回日期、時間或這兩者。These examples use the six SQL ServerSQL Server system functions that return current date and time values, to return the date, the time, or both. 由於這些範例會依序傳回值,因此其小數秒數可能會不同。The examples return the values in series, so their fractional seconds might differ. 請注意,傳回的實際值會反映實際執行日期/時間。Note that the actual values returned will reflect the actual day / time of execution.

A.A. 取得目前的系統日期和時間Get the Current System Date and Time

SELECT SYSDATETIME()  
    ,SYSDATETIMEOFFSET()  
    ,SYSUTCDATETIME()  
    ,CURRENT_TIMESTAMP  
    ,GETDATE()  
    ,GETUTCDATE();  
/* Returned:  
SYSDATETIME()      2007-04-30 13:10:02.0474381  
SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00  
SYSUTCDATETIME()   2007-04-30 20:10:02.0474381  
CURRENT_TIMESTAMP  2007-04-30 13:10:02.047  
GETDATE()          2007-04-30 13:10:02.047  
GETUTCDATE()       2007-04-30 20:10:02.047  
*/

B.B. 取得目前的系統日期Get the Current System Date

SELECT CONVERT (date, SYSDATETIME())  
    ,CONVERT (date, SYSDATETIMEOFFSET())  
    ,CONVERT (date, SYSUTCDATETIME())  
    ,CONVERT (date, CURRENT_TIMESTAMP)  
    ,CONVERT (date, GETDATE())  
    ,CONVERT (date, GETUTCDATE());  
  
/* Returned   
SYSDATETIME()      2007-05-03  
SYSDATETIMEOFFSET()2007-05-03  
SYSUTCDATETIME()   2007-05-04  
CURRENT_TIMESTAMP  2007-05-03  
GETDATE()          2007-05-03  
GETUTCDATE()       2007-05-04  
*/  

C.C. 取得目前的系統時間Get the Current System Time

SELECT CONVERT (time, SYSDATETIME())  
    ,CONVERT (time, SYSDATETIMEOFFSET())  
    ,CONVERT (time, SYSUTCDATETIME())  
    ,CONVERT (time, CURRENT_TIMESTAMP)  
    ,CONVERT (time, GETDATE())  
    ,CONVERT (time, GETUTCDATE());  
  
/* Returned  
SYSDATETIME()      13:18:45.3490361  
SYSDATETIMEOFFSET()13:18:45.3490361  
SYSUTCDATETIME()   20:18:45.3490361  
CURRENT_TIMESTAMP  13:18:45.3470000  
GETDATE()          13:18:45.3470000  
GETUTCDATE()       20:18:45.3470000  
*/  

範例:Azure SQL 資料倉儲Azure SQL Data Warehouse平行處理資料倉儲Parallel Data WarehouseExamples: Azure SQL 資料倉儲Azure SQL Data Warehouse and 平行處理資料倉儲Parallel Data Warehouse

SELECT CURRENT_TIMESTAMP;  

另請參閱See also

CAST 和 CONVERT (Transact-SQL)CAST and CONVERT (Transact-SQL)