SQL MONTH() Function

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

Overview

This article focuses on the understanding and usage of the SQL MONTH() function that is used in query languages.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Introduction to SQL MONTH()

The SQL MONTH() function returns the month of the date as an integer (a number from 1 to 12). We can either provide a datetime or date to get the month.

Syntax

The syntax of the SQL MONTH() function is as follows:

The keyword MONTH is written with parenthesis inside which one required parameter is passed.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Parameters/Arguments

We have already seen the syntax of the SQL MONTH() function. It is easier to guess the argument passed to the function:

Argument PassedDescription
Date/DateTimeIt is a required parameter. We specify the date/datetime from which we want to extract the month.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Return Value

There can be three types of the argument passed to the SQL MONTH() function:

  1. Date Type - When a date is passed to the function, it returns an integer between 1-12 where the numbers specify each month in numeric form.
  2. Time Type - When only a time value is passed to the function, the function returns 1.
  3. DateTime Type - When a datetime value is passed to the function, it works similarly as when we pass a value with only the date part.

How to use SQL MONTH()

There are multiple scenarios where the SQL MONTH() function facilitates our queries. Let us go through them one by one:

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example 1: Passing DateTime Argument to the Function

We know that argument can be of datetime type, hence let's see the output when a datetime parameter is passed to the function:

The above function will return integer 9.

Example 2: Passing a Time Argument to the Function

A unique scenario where the SQL compiler always returns 1 is when we only pass the time part of the datetime:

The above function will return integer 1.

Features of SQL MONTH()

There are some features of the SQL MONTH () function:

  1. It is used to extract the monthly data of the year for the argument passed.
  2. The function can accept time along with the date as an argument.
  3. It is a date function in SQL.
  4. Only one required parameter is passed to the function.

Conclusion

  1. The SQL MONTH() function returns the month as an integer for the specified date.
  2. There is only one argument passed that is required. The argument passed is of date type.
  3. When the argument passed is of date/datetime type, an integer between 1-12 is returned. Whereas, if only time is passed to the function, it returns 1 always.