Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Date Time FunctionsRSS Feeds

MONTH Function

Posted By: Sarita Patel     Category: SQL Server     Views: 4699

This article describes the use of MONTH function in sql server with different examples.

MONTH function is used to get month part of the specified date. 



Syntax of MONTH Function :

MONTH(date


date is an expression returning a datetime or smalldatetime or a character string in a date format.

IT returns an integer value.




Examples of MONTH Function :

Example 1 : Use of MONTH function in select clause

SELECT MONTH('11/30/2002')

Output
11

Above example returns month in numeric of specified string date.



Example 2 : Use of MONTH function in where clause

SELECT  ShipName, OrderDate
FROM     Orders
WHERE   DATEPART(MONTH,OrderDate) = MONTH('11/30/2002')

Output
ShipName                                OrderDate
White Clover Markets               1996-11-01 00:00:00.000
QUICK-Stop                           1996-11-04 00:00:00.000
Rattlesnake Canyon Grocery    1996-11-05 00:00:00.000
Familia Arquibaldo                   1996-11-06 00:00:00.000
Die Wandernde Kuh                 1996-11-07 00:00:00.000

Above example returns orders placed in 11th month.

  
Share: 

 
 
 

Didn't find what you were looking for? Find more on MONTH Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of MONTH Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!