New versions: Dev (3.14) | Latest (3.13) | 3.12

QUARTER

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Extract the QUARTER value from a datetime value.

The QUARTER function is a short version of the EXTRACT, passing a DatePart.QUARTER value as an argument.

SELECT quarter(DATE '2020-02-03');
create.select(quarter(Date.valueOf("2020-02-03"))).fetch();

The result being

+---------+
| quarter |
+---------+
|       1 |
+---------+

Dialect support

This example using jOOQ:

quarter(Date.valueOf("2020-02-03"))

Translates to the following dialect specific expressions:

-- ACCESS
(cdec(((datepart('m', #2020/02/03 00:00:00#) + 2) / 3)) - (((datepart('m', #2020/02/03 00:00:00#) + 2) / 3) < cdec(((datepart('m', #2020/02/03 00:00:00#) + 2) / 3))))

-- ASE, SYBASE
datepart(qq, '2020-02-03 00:00:00.0')

-- AURORA_MYSQL, MEMSQL, MYSQL
quarter({ts '2020-02-03 00:00:00.0'})

-- AURORA_POSTGRES, COCKROACHDB, POSTGRES
extract(QUARTER FROM TIMESTAMP '2020-02-03 00:00:00.0')

-- CUBRID
floor(((extract(MONTH FROM DATETIME '2020-02-03 00:00:00.0') + 2) / 3))

-- DB2, H2, HSQLDB, MARIADB
quarter(TIMESTAMP '2020-02-03 00:00:00.0')

-- DERBY
floor(((MONTH(TIMESTAMP('2020-02-03 00:00:00.0')) + 2) / 3))

-- FIREBIRD, HANA, INGRES, REDSHIFT, TERADATA, VERTICA
floor(((extract(MONTH FROM TIMESTAMP '2020-02-03 00:00:00.0') + 2) / 3))

-- INFORMIX
floor(((MONTH(DATETIME(2020-02-03 00:00:00.0) YEAR TO FRACTION) + 2) / 3))

-- ORACLE
to_number(to_char(TIMESTAMP '2020-02-03 00:00:00.0', 'Q'))

-- SQLDATAWAREHOUSE, SQLSERVER
datepart(qq, CAST('2020-02-03 00:00:00.0' AS DATETIME2))

-- SQLITE
(CAST(((strftime('%m', '2020-02-03 00:00:00.0') + 2) / 3) AS int8) - (((strftime('%m', '2020-02-03 00:00:00.0') + 2) / 3) < CAST(((strftime('%m', '2020-02-03 00:00:00.0') + 2) / 3) AS int8)))

(These are currently generated with jOOQ 3.14, see #10141)

The jOOQ Logo