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

DATEADD

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 date (represented by java.sql.Date).

SELECT DATE '2020-02-03' + 3;
create.select(dateAdd(Date.valueOf("2020-02-03"), 3)).fetch();

The result being

+------------+
| date_add   |
+------------+
| 2020-02-06 |
+------------+

Dialect support

This example using jOOQ:

dateAdd(Date.valueOf("2020-02-03"), 3)

Translates to the following dialect specific expressions:

-- ACCESS
dateadd('d', 3, #2020/02/03#)

-- ASE, SYBASE
dateadd(DAY, 3, '2020-02-03')

-- AURORA_MYSQL, MEMSQL, MYSQL
date_add({d '2020-02-03'}, INTERVAL 3 DAY)

-- AURORA_POSTGRES, COCKROACHDB, DUCKDB, EXASOL, H2, ORACLE, POSTGRES, REDSHIFT, VERTICA, YUGABYTEDB
(DATE '2020-02-03' + 3)

-- BIGQUERY
timestamp_add(DATE '2020-02-03', INTERVAL 3 DAY)

-- DB2, HSQLDB
(DATE '2020-02-03' + (3) day)

-- DERBY
CAST({fn timestampadd(SQL_TSI_DAY, 3, DATE('2020-02-03')) } AS DATE)

-- FIREBIRD, SNOWFLAKE
dateadd(DAY, 3, DATE '2020-02-03')

-- HANA
add_days(DATE '2020-02-03', 3)

-- INFORMIX
(DATETIME(2020-02-03) YEAR TO DAY + 3 UNITS DAY)

-- MARIADB
date_add(DATE '2020-02-03', INTERVAL 3 DAY)

-- SQLDATAWAREHOUSE, SQLSERVER
dateadd(DAY, 3, CAST('2020-02-03' AS date))

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

-- TERADATA
DATE '2020-02-03' + CAST(3 || ' 00:00:00' AS INTERVAL DAY TO SECOND)

-- TRINO
date_add('day', 3, DATE '2020-02-03')

(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