Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

MySQL Month Function

by suresh

MySQL Month Date Functions, which returns the Month number from a given date. This MySQL Month function returns integer range from 1 to 12 where 1 = January and 12 = December. The basic syntax of the Month Function is as shown below:

MONTH(date or expression);

MySQL Month function Example

This MySQL Month function returns 0 if the user-specified date argument is 0000-00-00 or 2019-00-00. Or Say, it returns 0 if the Zero Month part is given. The below shown queries help you understand the use of this Month function. Here, we are returning the Month numbers from the different date expression, and the Date & time expression.

SELECT MONTH('2015-12-22');

SELECT MONTH('2015-02-20 01:22:14');

SELECT MONTH('2016-08-20');
MySQL Month Function 1

MySQL Month Function Example 2

The following Date Function query shows you what happens when we try to return the month number from a date in string format. Here, we are returning month number from the current date and time returned by the Now() function, CURDATE() function, and UTC_TIMESTAMP function.

SELECT CURDATE(), MONTH(CURDATE());

SELECT NOW(), MONTH(NOW());

SELECT UTC_TIMESTAMP(), MONTH(UTC_TIMESTAMP());
MySQL Month Function 2

Here, we are trying to return the month number from YYYYMMDD, YYMMDD formats. Within the last MySQL statement, we used the zero month part. That’s why it returns NULL.

SELECT MONTH('20160922');

SELECT MONTH('160212');

SELECT MONTH('2019-00-00'), MONTH('0');
MySQL Month Function 3

Month Example 3

In this example, let us see how to use this Month function on a table. Here, we are returning the month number from the Hire Date column. For this Month function demo, we are using Workbench to write a query against the customer table.

SELECT EmpID,
FirstName,
LastName,
Occupation,
YearlyIncome,
Sales,
HireDate,
MONTH(HireDate)
FROM `MySQL Tutorial`.customer;
MySQL Month Function 4

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy