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 QUARTER Function

by suresh

MySQL Quarter function is one of the MySQL Date Functions, which is used to return the quarter of the year number from a given date. This Quarter function returns integer range from 1 to 4. The basic syntax of the Quarter Function in MySQL is as shown below:

QUARTER(date or expression);

TIP: This Quarter function returns 0 if the given date argument is 0000-00-00. Or Say, it returns 0 if the Zero date part is given.

MySQL Quarter function Example

The below shown queries help you understand the use of this Quarter function. Here, we are returning the Quarter numbers from the different date expression, and the Date & time expression.

SELECT QUARTER('2016-12-22');

SELECT QUARTER('2016-07-15');

SELECT QUARTER('2016-03-15 11:22:33');
MySQL QUARTER Function 1

Here, we are returning quarter of the year from the current date and time returned by the Now() and CURDATE() function.

SELECT CURDATE(), QUARTER(CURDATE());

SELECT NOW(), QUARTER(NOW());

SELECT QUARTER(CURDATE() + 20), QUARTER(NOW() + 2);
MySQL QUARTER Function 2

MySQL Quarter Function Example 2

The following query shows you what happens when we try to return the year quarter value from a date in string format. In this Date Function example, we are trying to return the quarter of the year from YYYYMMDD, YYMMDD, YYYYMMDDHHMMSS formats.

SELECT QUARTER(20190512);

SELECT QUARTER(750812);

SELECT QUARTER(20191112012233);
MySQL QUARTER Function 3

Here, we are trying to return the Quarter of the Year from an invalid date, and zero month part. That’s why MySQL returns NULL.

SELECT QUARTER(20190542);

SELECT QUARTER(2019-00-00);

SELECT QUARTER(CURDATE() + 45);
MySQL QUARTER Function 4

Quarter Example 3

In this instance, we show you how to use this Quarter function on a table. Here, we are returning the month number from the Hire Date column. For this MySQL Quarter function demo, we are using Workbench to write a query against the customer table.

SELECT EmpID,
FirstName,
LastName,
Occupation,
YearlyIncome,
Sales,
HireDate,
QUARTER(HireDate)
FROM `MySQL Tutorial`.customer;
MySQL QUARTER Function 5
\

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