SQL Server MONTH Function will return an integer that represents the month part of a specified date and its syntax is
For this Month Function example, we use the below-shown data
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]
MONTH Function Example 2
In this case, we will return the Month numbers from Hire Date in the Employee table. To achieve this, we are using both the DATEPART and Month functions. 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]
As you can see that the DATEPART and Month method return the same month result. Remember, before 2012, people used the DATEPART to extract the Month Number. Please refer to the DateTime method in Server for the Remaining methods.