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

LOCALDATETIMEADD

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

Add an interval of type java.lang.Number (number of days) or org.jooq.types.Interval (SQL interval type) to a timestamp (represented by java.time.LocalDateTime).

This does the same as TIMESTAMPADD except that the client type representation uses JSR-310 types.

SELECT DATE '2020-02-03 15:30:45' + INTERVAL 3 DAYS;
create.select(localDateTimeAdd(LocalDateTime.parse("2020-02-03T15:30:45"), 3)).fetch();

The result being

+---------------------+
| timestamp_add       |
+---------------------+
| 2020-02-06 15:30:45 |
+---------------------+

Dialect support

This example using jOOQ:

localDateTimeAdd(LocalDateTime.parse("2020-02-03T15:30:45"), 3)

Translates to the following dialect specific expressions:

Access

dateadd('d', 3, #2020/02/03 15:30:45#)

ASE, Sybase

dateadd(DAY, 3, '2020-02-03 15:30:45.0')

Aurora MySQL, MariaDB, MySQL

date_add(TIMESTAMP '2020-02-03 15:30:45.0', INTERVAL 3 DAY)

Aurora Postgres, CockroachDB, Postgres, Redshift, YugabyteDB

(TIMESTAMP '2020-02-03 15:30:45.0' + 3 * INTERVAL '1 day')

BigQuery

timestamp_add(DATETIME '2020-02-03 15:30:45.0', INTERVAL 3 DAY)

ClickHouse

(TIMESTAMP '2020-02-03 15:30:45' + 3)

DB2, HSQLDB

(TIMESTAMP '2020-02-03 15:30:45.0' + (3) day)

Derby

CAST({fn timestampadd(SQL_TSI_DAY, 3, TIMESTAMP('2020-02-03 15:30:45.0')) } AS TIMESTAMP)

DuckDB

date_add(TIMESTAMP '2020-02-03 15:30:45.0', INTERVAL 1 DAY * 3)

Exasol, H2, Oracle, Vertica

(TIMESTAMP '2020-02-03 15:30:45.0' + 3)

Firebird, Snowflake

dateadd(DAY, 3, TIMESTAMP '2020-02-03 15:30:45.0')

Hana

add_days(TIMESTAMP '2020-02-03 15:30:45.0', 3)

Informix

(DATETIME(2020-02-03 15:30:45.0) YEAR TO FRACTION + 3 UNITS DAY)

MemSQL

date_add({ts '2020-02-03 15:30:45.0'}, INTERVAL 3 DAY)

SQLDataWarehouse, SQLServer

dateadd(DAY, 3, CAST('2020-02-03 15:30:45.0' AS DATETIME2))

SQLite

strftime('%Y-%m-%d %H:%M:%f', '2020-02-03 15:30:45.0', (CAST(3 AS varchar) || ' day'))

Teradata

TIMESTAMP '2020-02-03 15:30:45.0' + CAST(3 || ' 00:00:00' AS INTERVAL DAY TO SECOND)

Trino

date_add('day', 3, TIMESTAMP '2020-02-03 15:30:45.0')
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