Bewerken

Delen via


MONTH (Transact-SQL)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)

Returns an integer that represents the month of the specified date.

For an overview of all Transact-SQL date and time data types and functions, see Date and Time Data Types and Functions (Transact-SQL).

Transact-SQL syntax conventions

Syntax

MONTH ( date )  

Arguments

date
Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. The date argument can be an expression, column expression, user-defined variable, or string literal.

Return Type

int

Return Value

MONTH returns the same value as DATEPART (month, date).

If date contains only a time part, the return value is 1, the base month.

Examples

The following statement returns 4. This is the number of the month.

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

The following statement returns 1900, 1, 1. The argument for date is the number 0. SQL Server interprets 0 as January 1, 1900.

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

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

The 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;  

The following example returns 1900, 1, 1. The argument for date is the number 0. SQL Server interprets 0 as January 1, 1900.

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

See Also

CAST and CONVERT (Transact-SQL)