What is QUARTER() in SQL?

The QUARTER() function returns which quarter of the year a date is in when a date is sent as a parameter.

Figure 1 shows a visual representation of the QUARTER() function and the quarters.

Figure 1: Visual representation of the QUARTER() function and the quarters

Syntax

QUARTER(date)

Parameter

The QUARTER() function takes the date as a parameter.

Dates must be written in the YYYY-MM-DD format, else this function returns NULL.

Return value

The QUARTER() function returns the quarter of the year a date is in when a date is sent as a parameter.

It returns NULL if the date is invalid.

Example

The following example shows how we can isolate the quarter from the admission date of students using the QUARTER() function.

Students

Student ID

Student Name

Student Admission Date

1

David

2000-07-14

2

Luiss

2002-08-15

3

Harvey

2005-04-19

4

Lucy

2010-01-27

5

Andrew

2011-10-03

SELECT *, QUARTER(studentAdmissionDate) as QUARTER
from Students;

Free Resources