SQL MONTH Function

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


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

SQL MONTH Function 1

SQL MONTH Function Example 1

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

-- Example for SQL MONTH Function

-- Testing Month Function with Random Date 
SELECT MONTH('07-19-2004') AS [Day Example]

-- Testing Month Function with Random Date and Time 
SELECT MONTH('2015-11-24 12:29:44.513') AS [Day Example]

-- Testing Month Function with 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 Function and Month function. It demonstrates that you can get the month number using both these functions.

-- Example for SQL MONTH Function
USE [SQL Tutorial]
      ,[FirstName] + ' '+ [LastName] AS [Full Name]
      ,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 function, and Month function are returning the same month result. Remember, before 2012 people used the DATEPART function to extract the Month Number. Please refer to Date and Time Function in SQL Server for the Remaining Functions.