Available in versions: Dev (3.19) | Latest (3.18) | 3.17 | 3.16 | 3.15 | 3.14 | 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, SNOWFLAKE, YUGABYTEDB
extract(QUARTER FROM TIMESTAMP '2020-02-03 00:00:00.0')

-- BIGQUERY
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))

-- DUCKDB, EXASOL, FIREBIRD, HANA, REDSHIFT, TERADATA, TRINO, 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
floor(((CAST(strftime('%m', '2020-02-03 00:00:00.0') AS int) + 2) / 3))

(These are currently generated with jOOQ 3.19, see #10141), or translate your own on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo