MONTH (Transact-SQL)MONTH (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

傳回代表指定 date 中月份的整數。Returns an integer that represents the month of the specified date.

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

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

語法Syntax

MONTH ( date )  

引數Arguments

datedate
這是可解析成 timedatesmalldatetimedatetimedatetime2datetimeoffset 值的運算式。Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. date 引數可以是運算式、資料行運算式、使用者自訂變數或字串常值。The date argument can be an expression, column expression, user-defined variable, or string literal.

傳回類型Return Type

intint

傳回值Return Value

MONTH 會傳回與 DATEPART (month, date) 相同的值。MONTH returns the same value as DATEPART (month, date).

如果 date 僅包含時間部分,傳回值就是 1 (基底月份)。If date contains only a time part, the return value is 1, the base month.

範例Examples

下列陳述式會傳回 4The following statement returns 4. 這是月份。This is the number of the month.

SELECT MONTH('2007-04-30T01:01:01.1234567 -07:00');  

下列陳述式會傳回 1900, 1, 1The following statement returns 1900, 1, 1. date 的引數是數字 0The argument for date is the number 0. SQL ServerSQL Server 會將 0 解譯為 1900 年 1 月 1 日。interprets 0 as January 1, 1900.

SELECT YEAR(0), MONTH(0), DAY(0);  

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

下列範例會傳回 4The following example returns 4. 這是月份。This is the number of the month.

-- Uses AdventureWorks  
  
SELECT TOP 1 MONTH('2007-04-30T01:01:01.1234')   
FROM dbo.DimCustomer;  

下列範例會傳回 1900, 1, 1The following example returns 1900, 1, 1. date 的引數是數字 0The argument for date is the number 0. SQL ServerSQL Server 會將 0 解譯為 1900 年 1 月 1 日。interprets 0 as January 1, 1900.

-- Uses AdventureWorks  
  
SELECT TOP 1 YEAR(0), MONTH(0), DAY(0) FROM dbo.DimCustomer;  

另請參閱See Also

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