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

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(DD, 3, '2020-02-03')

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

-- AURORA_POSTGRES, COCKROACHDB, POSTGRES, REDSHIFT
(DATE '2020-02-03' + 3)

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

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

-- DB2
(DATE '2020-02-03' + 3 DAY)

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

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

-- H2
dateadd('day', 3, DATE '2020-02-03')

-- HSQLDB
{fn timestampadd(SQL_TSI_DAY, 3, DATE '2020-02-03') }

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

-- ORACLE
(DATE '2020-02-03' + numtodsinterval(3, 'day'))

-- SQLDATAWAREHOUSE, SQLSERVER
dateadd(DD, 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 AS INTERVAL DAY (4)))

-- VERTICA
(DATE '2020-02-03' + CAST(3 AS INTERVAL DAY))

(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