All Products
Search
Document Center

Realtime Compute for Apache Flink:DATE_SUB

Last Updated:Mar 26, 2026

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

ParameterData typeDescription
startdateVARCHARThe start date. Accepted formats: yyyy-MM-dd and yyyy-MM-dd HH:mm:ss.
timeTIMESTAMPThe start timestamp.
daysINTThe 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-15NULL

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-152017-09-15NULL

Both date1 (a VARCHAR date) and the TIMESTAMP literal produce the same result. nullstr returns NULL because the input is NULL.

Related functions

  • DATE_ADD: Adds days to a date.

  • DATEDIFF: Calculates the number of days between two dates.