New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3 | 2.6

TRUNC

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

Truncate a datetime value to the precision of a certain org.jooq.DatePart, or DatePart.DAY by default.

SELECT TRUNC(DATE '2020-02-03', 'YYYY');
create.select(trunc(Date.valueOf("2020-02-03", DatePart.YEAR))).fetch();

The result being

+------------+
| trunc      |
+------------+
| 2020-01-01 |
+------------+

Dialect support

This example using jOOQ:

trunc(Date.valueOf("2020-02-03"), DatePart.YEAR)

Translates to the following dialect specific expressions:

-- ASE, SYBASE
trunc('2020-02-03', NULL)

-- AURORA_MYSQL, MEMSQL, MYSQL
trunc({d '2020-02-03'}, NULL)

-- AURORA_POSTGRES, POSTGRES, VERTICA
date_trunc('year', DATE '2020-02-03')

-- BIGQUERY, EXASOL, FIREBIRD, HANA, INGRES, MARIADB, TERADATA
trunc(DATE '2020-02-03', NULL)

-- CUBRID, HSQLDB
trunc(DATE '2020-02-03', 'YY')

-- DB2, ORACLE
trunc(DATE '2020-02-03', 'YYYY')

-- DERBY
trunc(DATE('2020-02-03'), NULL)

-- H2
PARSEDATETIME(FORMATDATETIME(DATE '2020-02-03', 'yyyy'), 'yyyy')

-- INFORMIX
trunc(DATETIME(2020-02-03) YEAR TO DAY, 'YEAR')

-- SQLDATAWAREHOUSE, SQLSERVER
trunc(CAST('2020-02-03' AS date), NULL)

-- ACCESS, COCKROACHDB, IGNITE, REDSHIFT, SNOWFLAKE, SQLITE
/* UNSUPPORTED */

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

Feedback

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

The jOOQ Logo