SQL MONTH Function

SQL MONTH Function will return an integer that represents the month part of a specified date. The syntax of the MONTH method is

MONTH(date)

For this Month Function in SQL Server example, we use the below-shown data

Employee Table for MONTH Function 1

SQL MONTH Function Example

In this example, we will show you the possible ways to use the Month.

SELECT MONTH('07-19-2004') AS [Day Example]

-- Testing with RandomTime 
SELECT MONTH('2015-11-24 12:29:44.513') AS [Day Example]

-- Testing with Today
SELECT MONTH(GETDATE()) AS [Todays Date]
SQL MONTH Function 2

MONTH Function Example 2

In this case, we will return the Month numbers from Hire Date in Employee table. To achieve this, we are using both the DATEPART and Month function. It demonstrates that you can get the month number using both these methods.

SELECT [EmpID]
      ,[FirstName] + ' '+ [LastName] AS [Full Name]
      ,[Occupation]
      ,[YearlyIncome]
      ,[HireDate]
      ,MONTH([HireDate]) AS [Month Number]
      ,DATEPART(month, [HireDate]) AS [This Month From DatePart]
  FROM [Employee]
SQL MONTH Function 3

As you can see that the DATEPART, and Month method are returning the same month result. Remember, before 2012 people used the DATEPART to extract the Month Number. Please refer to DateTime method in SQL Server for the Remaining methods.