The DATEADD
function adds a specified number of days, months, years, or fractional years to a date or interval.
DATEADD ( date-part , date-or-interval , number-of-units )
day
month
year
quarter
date-part
is year
, the number-of-units
must be a fractional number.
SELECT DATEADD(day, 7, GETDATE()); -- Adds 7 days to the current date.
SELECT DATEADD(month, 3, '2023-10-26'); -- Adds 3 months to 2023-10-26, resulting in 2024-01-26.
SELECT DATEADD(year, 5, '2020-01-01'); -- Adds 5 years to 2020-01-01, resulting in 2025-01-01.