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.
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.
SELECT MONTH('2020/01/02');
Output :
1Example-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 :
7Example-3 : Using MONTH() function with date as parameter which includes time as well.
SELECT MONTH('2018/11/22 07:44');
Output :
11Example-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 :
9Application : This function is used to find the month of the year from the date specified.