Subtracts a specified number of days from a date and returns the result as a DATE value.
Limitations
Requires Ververica Runtime (VVR) 3.0.0 or later in Realtime Compute for Apache Flink.
Syntax
DATE DATE_SUB(VARCHAR startdate, INT days)
DATE DATE_SUB(TIMESTAMP time, INT days)Parameters
| Parameter | Data type | Description |
|---|---|---|
startdate | VARCHAR | The start date. Accepted formats: yyyy-MM-dd and yyyy-MM-dd HH:mm:ss. |
time | TIMESTAMP | The start timestamp. |
days | INT | The number of days to subtract. |
Note If any input parameter is
NULL or a parsing error occurs, the function returns NULL.Example
The following example subtracts 30 days from three different inputs: a VARCHAR date column, a TIMESTAMP literal, and a NULL value.
Test data
| date1 (VARCHAR) | nullstr (VARCHAR) |
|---|---|
| 2017-10-15 | NULL |
Test statement
SELECT DATE_SUB(date1, 30) AS var1,
DATE_SUB(TIMESTAMP '2017-10-15 23:00:00', 30) AS var2,
DATE_SUB(nullstr, 30) AS var3
FROM T1;Result
| var1 (DATE) | var2 (DATE) | var3 (DATE) |
|---|---|---|
| 2017-09-15 | 2017-09-15 | NULL |
Both date1 (a VARCHAR date) and the TIMESTAMP literal produce the same result. nullstr returns NULL because the input is NULL.