By: Daniel Calbimonte
The MONTH function returns the month part of the date as an integer from the date or datetime provided.
Syntax
MONTH(date)
Parameters
- Date – Is the date or datetime provided
Simple MONTH Example
The following example will show the month of March 9, 2021.
SELECT MONTH('3-9-2021 5:00:55 PM') as MONTH
MONTH function with NULL values
If the parameter of the MONTH function is NULL, a NULL value will be returned.
SELECT MONTH(NULL) as MONTH
Conversion failed error for the MONTH function
A typical error will occur if the date is invalid. The following example is using a wrong month number (13).
SELECT MONTH('13-02-2021 5:00:55 PM') as MONTH
The error message displayed is as follows:
Conversion failed when converting date and/or time from character string.
Using Time with MONTH function
If the MONTH function receives a time parameter, the value returned is 1.
SELECT MONTH('5:00:55 PM') as MONTH
MONTH function with Table Data
The following example will show the month of the StartDate.
SELECT StartDate, MONTH(StartDate) as MONTH FROM [Production].[ProductCostHistory]
Related Articles
- SQL DAY
- SQL YEAR
- Mimic timestamp behavior of other database platforms to store last modified date
- SQL Convert Date to YYYYMMDD
- SQL Server DIFFERENCE Function
- SQL Server CONCAT Function
- Format SQL Server Dates with FORMAT Function
- DATEDIFF SQL Server Function
Last Update: 1/4/2022