DATEFROMPARTS (Transact-SQL)DATEFROMPARTS (Transact-SQL)

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

此函式會傳回對應至指定年份、月份和日期值的 date 值。This function returns a date value that maps to the specified year, month, and day values.

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

語法Syntax

DATEFROMPARTS ( year, month, day )  

引數Arguments

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

monthmonth
指定月份的整數運算式,從 1 到 12。An integer expression that specifies a month, from 1 to 12.

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

傳回類型Return types

datedate

RemarksRemarks

DATEFROMPARTS 會傳回 date 值,其中日期部分會設為指定的年、月、日,而時間部分則會設為預設值。DATEFROMPARTS returns a date value, with the date portion set to the specified year, month and day, and the time portion set to the default. 若引數無效,DATEFROMPARTS 會引發錯誤。For invalid arguments, DATEFROMPARTS will raise an error. 如果至少一個必要引數具有 Null 值,則 DATEFROMPARTS 會傳回 Null。DATEFROMPARTS returns null if at least one required argument has a null value.

此函式可以遠端處理到 SQL Server 2012 (11.x)SQL Server 2012 (11.x) 伺服器及更新版本。This function can handle remoting to SQL Server 2012 (11.x)SQL Server 2012 (11.x) servers and above. 它無法遠端處理到版本低於 SQL Server 2012 (11.x)SQL Server 2012 (11.x) 的伺服器。It cannot handle remoting to servers with a version below SQL Server 2012 (11.x)SQL Server 2012 (11.x).

範例Examples

此範例示範 DATEFROMPARTS 函式的運作。This example shows the DATEFROMPARTS function in action.

SELECT DATEFROMPARTS ( 2010, 12, 31 ) AS Result;  

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

Result  
----------------------------------  
2010-12-31  
  
(1 row(s) affected)  

另請參閱See also

日期 (Transact-SQL)date (Transact-SQL)