DATETIMEFROMPARTS (Transact-SQL)DATETIMEFROMPARTS (Transact-SQL)

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

此函式會傳回指定日期和時間引數的 datetime 值。This function returns a datetime value for the specified date and time arguments.

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

語法Syntax

DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )  

引數Arguments

yearyear
指定年份的整數運算式。An integer expression that specifies a year.

monthmonth
指定月份的整數運算式。An integer expression that specifies a month.

dayday
指定日期的整數運算式。An integer expression that specifies a day.

hourhour
指定小時的整數運算式。An integer expression that specifies hours.

minuteminute
指定分鐘的整數運算式。An integer expression that specifies minutes.

secondsseconds
指定秒的整數運算式。An integer expression that specifies seconds.

millisecondsmilliseconds
指定毫秒的整數運算式。An integer expression that specifies milliseconds.

傳回類型Return types

datetimedatetime

RemarksRemarks

DATETIMEFROMPARTS 會傳回完整初始化的 datetime 值。DATETIMEFROMPARTS returns a fully initialized datetime value. 如果至少一個必要引數具有無效的值,DATETIMEFROMPARTS 會引發錯誤。DATETIMEFROMPARTS will raise an error if at least one required argument has an invalid value. 如果至少一個必要引數具有 Null 值,則 DATETIMEFROMPARTS 會傳回 Null。DATETIMEFROMPARTS returns null if at least one required argument has a null value.

此函式支援遠端處理到 SQL Server 2017SQL Server 2017 伺服器及更新版本。This function supports remoting to SQL Server 2017SQL Server 2017 servers and above. 它不支援遠端處理到版本低於 SQL Server 2017SQL Server 2017 的伺服器。It will not support remoting to servers that have a version below SQL Server 2017SQL Server 2017.

範例Examples

SELECT DATETIMEFROMPARTS ( 2010, 12, 31, 23, 59, 59, 0 ) AS Result;  

以下為結果集:Here is the result set.

Result  
---------------------------  
2010-12-31 23:59:59.000  
  
(1 row(s) affected)  

另請參閱See also

datetime (Transact-SQL)datetime (Transact-SQL)