Available in versions: Dev (3.19) | Latest (3.18) | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10 | 3.9

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:

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

-- BIGQUERY
date_trunc(
  DATE '2020-02-03',
  YEAR
)

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

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

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

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

-- ACCESS, ASE, AURORA_MYSQL, DERBY, DUCKDB, EXASOL, FIREBIRD, HANA, MARIADB, MEMSQL, MYSQL, REDSHIFT, SNOWFLAKE, 
-- SQLDATAWAREHOUSE, SQLITE, SQLSERVER, SYBASE, TERADATA, TRINO, YUGABYTEDB
/* UNSUPPORTED */

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

References to this page

Feedback

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

The jOOQ Logo