Mysql Quarter Function

MySQL: QUARTER Function

This tutorial explains how to use the MySQL QUARTER function with syntax and examples.

Description

The MySQL QUARTER function returns the quarter portion of a date value.

Syntax

The syntax for the QUARTER function in MySQL is:

QUARTER( date_value )

Parameters or Arguments

date_value

A date or datetime value from which to extract the quarter.

Note

  • The QUARTER function returns the quarter (a number from 1 to 4) given a date value.
  • Dates that have a month of Jan-Mar would return 1.
  • Dates that have a month of Apr-Jun would return 2.
  • Dates that have a month of Jul-Sep would return 3.
  • Dates that have a month of Oct-Dec would return 4.
  • See also the EXTRACT, YEAR, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, and MICROSECOND functions.

Applies To

The QUARTER function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL QUARTER function examples and explore how to use the QUARTER function in MySQL.

For example:

mysql> SELECT QUARTER('2014-01-28');
Output: 1

mysql> SELECT QUARTER('2014-01-28 15:21:05');
Output: 1

mysql> SELECT QUARTER('2013-04-20');
Output: 2

mysql> SELECT QUARTER('2013-07-16');
Output: 3

mysql> SELECT QUARTER('2013-10-15');
Output: 4

This last QUARTER example would display the quarter portion of the current system date (current system date is returned by the CURDATE function).

mysql> SELECT QUARTER(CURDATE());