MONTH (Transact-SQL)
Returns an integer representing the month part of a date or datetime expression.
Syntax
MONTH ( date_expression )
Arguments
date_expression- Is an expression of the date, datetime, datetime2, or smalldatetime data type.
Return Type
INT
Examples
A. Returning the month of the current date
The following example returns the month of the current date.
SELECT MONTH(GETDATE()) AS MonthNumber;
Result:
MonthNumber
-----------
10
B. Returning the month from a datetime column
The following example returns the month from the ModifiedDate column in the Production.Product table.
USE AdventureWorks2019;
GO
SELECT MONTH(ModifiedDate) AS MonthOfProductUpdate
FROM Production.Product
WHERE ProductID = 707;
GO
Result:
MonthOfProductUpdate
--------------------
7
C. Using MONTH to filter data
The following example returns all the orders placed in July.
USE AdventureWorks2019;
GO
SELECT SalesOrderID, OrderDate
FROM Sales.SalesOrderHeader
WHERE MONTH(OrderDate) = 7;
GO
Remarks
The MONTH function is the equivalent of using DATEPART(month, date_expression).
Note: If the
date_expression is NULL, MONTH returns NULL.