Updated on 2026-11-06 GMT+08:00
DATE_SUB
Syntax
STRING DATE_SUB(STRING startdate, INT days) STRING DATE_SUB(TIMESTAMP time, INT days)
Description
The DATE_SUB function is used to return the date obtained by subtracting a specified number of days from a date. If the target number of days is negative, the corresponding number of days is added.
Parameter Description
- Date: The data type is TIMESTAMP or STRING (format: yyyy-MM-dd HH:mm:ss). The value can be NULL.
- Number of days to add: The data type is INT.
- Return date: The date obtained by subtracting the specified number of days from the date. The data type is STRING.
Example
CREATE TABLE source (
time1 TIMESTAMP
) WITH (
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE Sink (
date1 string,
date2 string,
date3 string
) with ('connector' = 'print');
INSERT into
Sink
select
DATE_SUB(time1,30) as date1,
DATE_SUB('2017-09-15 00:00:00', 30) as date2,
DATE_SUB(cast(null as timestamp),30) as date3
FROM source | date1 (string) | date2 (string) | date3 (string) |
|---|---|---|
| 2024-04-29 | 2017-08-16 | null |
Parent topic: Enhanced Functions
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot