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
DATESUB
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Subtract an interval of type java.lang.Number
(number of days) or org.jooq.types.Interval
(SQL interval type) from a date (represented by java.sql.Date
).
SELECT DATE '2020-02-03' - 2;
create.select(dateSub(Date.valueOf("2020-02-03"), 2)).fetch();
The result being
+------------+ | date_sub | +------------+ | 2020-02-01 | +------------+
Dialect support
This example using jOOQ:
dateSub(Date.valueOf("2020-02-03"), 2)
Translates to the following dialect specific expressions:
-- ACCESS dateadd('d', -2, #2020/02/03#) -- ASE, SYBASE dateadd(DAY, -2, '2020-02-03') -- AURORA_MYSQL, MEMSQL, MYSQL date_add({d '2020-02-03'}, INTERVAL -2 DAY) -- AURORA_POSTGRES, COCKROACHDB, POSTGRES, REDSHIFT, YUGABYTEDB (DATE '2020-02-03' + -2) -- BIGQUERY timestamp_sub(DATE '2020-02-03', INTERVAL 2 DAY) -- DB2, HSQLDB (DATE '2020-02-03' - (2) day) -- DERBY CAST({fn timestampadd(SQL_TSI_DAY, -2, DATE('2020-02-03')) } AS DATE) -- DUCKDB, EXASOL, H2, ORACLE, VERTICA (DATE '2020-02-03' - 2) -- FIREBIRD, SNOWFLAKE dateadd(DAY, -2, DATE '2020-02-03') -- HANA add_days(DATE '2020-02-03', -2) -- INFORMIX (DATETIME(2020-02-03) YEAR TO DAY - 2 UNITS DAY) -- MARIADB date_add(DATE '2020-02-03', INTERVAL -2 DAY) -- SQLDATAWAREHOUSE, SQLSERVER dateadd(DAY, -2, CAST('2020-02-03' AS date)) -- SQLITE strftime('%Y-%m-%d %H:%M:%f', '2020-02-03', (CAST(-2 AS varchar) || ' day')) -- TERADATA DATE '2020-02-03' - CAST(2 || ' 00:00:00' AS INTERVAL DAY TO SECOND) -- TRINO date_add('day', -2, 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!