Available in versions: Dev (3.20) | Latest (3.19) | 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, DB2, H2, HSQLDB, MariaDB, MySQL

quarter(TIMESTAMP '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))

ClickHouse

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

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

MemSQL

quarter({ts '2020-02-03 00:00:00.0'})

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))
Generated with jOOQ 3.20. Translate your own SQL on our website

Feedback

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

The jOOQ Logo