MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB QUARTER() Function



The MariaDB QUARTER() function returns the quarter portion of a given date or datetime value. It can be between 1-4.

  • For January-March month it returns 1.
  • For April-June month it returns 2.
  • For July-September month it returns 3.
  • For October-December month it returns 4.

Syntax

QUARTER(datetime)

Parameters

datetime Required. Specify a date or datetime value from which to extract the quarter.

Return Value

Returns the quarter portion of a given date or datetime value.

Example 1:

The example below shows the usage of QUARTER() function.

SELECT QUARTER('2018-08-18');
Result: 3

SELECT QUARTER('2018-08-18 10:38:42');
Result: 3

SELECT QUARTER('2018-08-18 10:38:42.000004');
Result: 3

SELECT QUARTER('2018-02-18');
Result: 1

SELECT QUARTER('2018-04-18');
Result: 2

SELECT QUARTER('2018-11-18');
Result: 4

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56
501.802019-01-16 11:52:05
2001.722020-02-06 09:31:34

The statement given below can be used to get the quarter portion of records of column OrderTime:

SELECT *, QUARTER(OrderTime) AS QUARTER_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeQUARTER_Value
1001.582017-08-18 10:38:423
1201.612018-03-23 07:14:161
1251.782018-09-12 05:25:563
501.802019-01-16 11:52:051
2001.722020-02-06 09:31:341

❮ MariaDB Functions