This function is used to calculate the number of days in which start_date is increased by days.
To obtain the date with a specified change range based on the current date, use this function together with the current_date or getdate function.
Note that the logic of this function is opposite to that of the date_sub function.
date_add(string startdate, int days)
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
start_date |
Yes |
DATE or STRING |
Start date The following formats are supported:
|
days |
Yes |
BIGINT |
Number of days to be added
|
The return value is of the DATE type, in the yyyy-mm-dd format.
The value 2023-03-01 is returned after one day is added.
select date_add('2023-02-28 00:00:00', 1);
The value 2023-02-27 is returned after one day is subtracted.
select date_add(date '2023-02-28', -1);
The value 2023-03-20 is returned.
select date_add('2023-02-28 00:00:00', 20);
If the current time is 2023-08-14 16:00:00, 2023-08-13 is returned.
select date_add(getdate(),-1);
The value NULL is returned.
select date_add('2023-02-28 00:00:00', null);