QUARTER Function
The QUARTER function returns an integer in the range 1 through 4 that corresponds to the quarter of the calendar year that includes its DATE or DATETIME argument.
For example, any date in January, February, or March returns
the integer 1
.
The argument must be an expression that evaluates to a DATE or DATETIME data type.
Examples of QUARTER function expressions
The
following function expression returns
3
, because
August is in the third quarter of the year.QUARTER('2014-08-25')
The
following example returns a number that can range from
1
through 4
to
indicate the quarter when the order was placed: SELECT order_num, QUARTER(order_date) FROM orders;
The
following query includes QUARTER function expressions whose arguments
are the order_date column and the CURRENT operator.
The WHERE clause restricts the result set to qualifying rows with order_date values
in quarters earlier in the current year than the current quarter:
SELECT * FROM orders WHERE (QUARTER(order_date) < QUARTER(CURRENT)) AND YEAR(order_date) = YEAR(CURRENT);During the first quarter, however, this query returns no rows, because there can be no data from a quarter with a value less than the current quarter. That is, there is no quarter of value zero.