Open In App

MONTH() Function in SQL Server

Last Updated : 11 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

MONTH() function :
This function in SQL Server is used to return the month of the year i.e, from 1 to 12 for a date stated.

Features :

  • This function is used to find the month of the year for a date specified.
  • This function comes under Date Functions.
  • This function accepts only one parameter i.e, date.
  • This function can also include time with the stated date.

Syntax :

MONTH(date)

Parameter :
This method accepts only one parameter as given below :

  • date : Specified date from which the month of the year is to be returned.

Returns :
It returns the month of the year i.e, from 1 to 12 for a date specified.

Example-1 :
Using MONTH() function and getting the month of the year from the date specified.

SELECT MONTH('2020/01/02');

Output :

1

Example-2 :
Using MONTH() function with a variable and getting the month of the year from the date specified.

DECLARE @date VARCHAR(50);
SET @date = '2020/07/05';
SELECT MONTH(@date);

Output :

7

Example-3 :
Using MONTH() function with date as parameter which includes time as well.

SELECT MONTH('2018/11/22 07:44');

Output :

11

Example-4 :
Using MONTH() function with a variable and a date as parameter which includes time as well.

DECLARE @date VARCHAR(50);
SET @date = '2020/09/30 23:59';
SELECT MONTH(@date);

Output :

9

Application :
This function is used to find the month of the year from the date specified.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads