MySQL QUARTER() Function

The QUARTER() function in MySQL extracts the quarter of the year from a date or datetime value. This is particularly useful for working with quarterly data, generating quarterly reports, or performing quarterly data analysis.



QUARTER(): Definition and Usage

QUARTER() takes a date or datetime value as input and returns an integer (1-4) representing the quarter of the year that the date falls into. The quarters are defined as follows:

  • Quarter 1 (1): January, February, March
  • Quarter 2 (2): April, May, June
  • Quarter 3 (3): July, August, September
  • Quarter 4 (4): October, November, December

Syntax

Syntax

QUARTER(date)
      

Parameter Values

Parameter Description
date The date or datetime value. This is required.

Examples

Extracting the Quarter from a Date

This example shows how to get the quarter of the year for June 15th, 2017 (which is the second quarter).

Syntax

SELECT QUARTER("2017-06-15");
      
Output

2
      

Extracting the Quarter from a DateTime Value

This example demonstrates that QUARTER() works correctly with datetime values.

Syntax

SELECT QUARTER("2017-01-01 09:34:21");
      
Output

1
      

Extracting the Current Quarter

This gets the current quarter of the year.

Syntax

SELECT QUARTER(CURDATE());
      
Output

(The current quarter of the year, a number between 1 and 4)