GETUTCDATE (Transact-SQL)GETUTCDATE (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

將目前的資料庫系統時間戳記作為 datetime 值傳回。Returns the current database system timestamp as a datetime value. 不包含資料庫時區位移。The database time zone offset is not included. 這個值代表目前 UTC 時間 (國際標準時間)。This value represents the current UTC time (Coordinated Universal Time). 這個值衍生自正在執行 SQL ServerSQL Server 執行個體之電腦的作業系統。This value is derived from the operating system of the computer on which the instance of SQL ServerSQL Server is running.

注意

SYSDATETIME 和 SYSUTCDATETIME 比 GETDATE 和 GETUTCDATE 具有更多小數秒數有效位數。SYSDATETIME and SYSUTCDATETIME have more fractional seconds precision than GETDATE and GETUTCDATE. SYSDATETIMEOFFSET 包含系統時區位移。SYSDATETIMEOFFSET includes the system time zone offset. SYSDATETIME、SYSUTCDATETIME 和 SYSDATETIMEOFFSET 可指派給任何日期和時間類型的變數。SYSDATETIME, SYSUTCDATETIME, and SYSDATETIMEOFFSET can be assigned to a variable of any of the date and time types.

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

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

語法Syntax

GETUTCDATE()  

傳回類型Return Types

datetimedatetime

RemarksRemarks

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

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

範例Examples

下列範例會使用六個可傳回目前日期和時間的 SQL ServerSQL Server 系統函數來傳回日期、時間或這兩者。The following examples use the six SQL ServerSQL Server system functions that return current date and time to return the date, time or both. 由於這些值會依序傳回,因此其小數秒數可能會不同。The values are returned in series; therefore, their fractional seconds might be different.

A.A. 取得目前的系統日期和時間Getting the current system date and time

SELECT 'SYSDATETIME()      ', SYSDATETIME();  
SELECT 'SYSDATETIMEOFFSET()', SYSDATETIMEOFFSET();  
SELECT 'SYSUTCDATETIME()   ', SYSUTCDATETIME();  
SELECT 'CURRENT_TIMESTAMP  ', CURRENT_TIMESTAMP;  
SELECT 'GETDATE()          ', GETDATE();  
SELECT 'GETUTCDATE()       ', GETUTCDATE();  
/* Returned:  
SYSDATETIME()            2007-05-03 18:34:11.9351421  
SYSDATETIMEOFFSET()      2007-05-03 18:34:11.9351421 -07:00  
SYSUTCDATETIME()         2007-05-04 01:34:11.9351421  
CURRENT_TIMESTAMP        2007-05-03 18:34:11.933  
GETDATE()                2007-05-03 18:34:11.933  
GETUTCDATE()             2007-05-04 01:34:11.933  
*/  

B.B. 取得目前的系統日期Getting the current system date

SELECT 'SYSDATETIME()      ', CONVERT (date, SYSDATETIME());  
SELECT 'SYSDATETIMEOFFSET()', CONVERT (date, SYSDATETIMEOFFSET());  
SELECT 'SYSUTCDATETIME()   ', CONVERT (date, SYSUTCDATETIME());  
SELECT 'CURRENT_TIMESTAMP  ', CONVERT (date, CURRENT_TIMESTAMP);  
SELECT 'GETDATE()          ', CONVERT (date, GETDATE());  
SELECT 'GETUTCDATE()       ', 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. 取得目前的系統時間Getting the current system time

SELECT 'SYSDATETIME()      ', CONVERT (time, SYSDATETIME());  
SELECT 'SYSDATETIMEOFFSET()', CONVERT (time, SYSDATETIMEOFFSET());  
SELECT 'SYSUTCDATETIME()   ', CONVERT (time, SYSUTCDATETIME());  
SELECT 'CURRENT_TIMESTAMP  ', CONVERT (time, CURRENT_TIMESTAMP);  
SELECT 'GETDATE()          ', CONVERT (time, GETDATE());  
SELECT 'GETUTCDATE()       ', CONVERT (time, GETUTCDATE());  
/* Returned  
SYSDATETIME()            18:25:01.6958841  
SYSDATETIMEOFFSET()      18:25:01.6958841  
SYSUTCDATETIME()         01:25:01.6958841  
CURRENT_TIMESTAMP        18:25:01.6930000  
GETDATE()                18:25:01.6930000  
GETUTCDATE()             01:25:01.6930000  
*/  

另請參閱See Also

CAST 和 CONVERT (Transact-SQL) CAST and CONVERT (Transact-SQL)
AT TIME ZONE (Transact-SQL)AT TIME ZONE (Transact-SQL)