SQL Server DATEADD with Variables
SQL Server DATEADD with Variables is a SQL function in the Date/Time Functions category. SQL Server: adds a specified number of date parts to a date. Can use variables for dynamic intervals. The syntax is DATEADD(datepart, number, date). It accepts datepart, number, date. It returns date with added interval. A typical example: DECLARE @interval INT = 30; DECLARE @unit NVARCHAR(10) = 'DAY'; SELECT DATEADD(DAY, @interval, GETDATE()) AS future_date; -- 30 days from now -- Common dateparts: SELECT DATEADD(YEAR, 1, '2026-06-06'); -- 2027-06-06 SELECT DATEADD(MONTH, -3, '2026-06-06'); -- 2026-03-06 SELECT DATEADD(HOUR, 8, '2026-06-06'); -- 2026-06-06 08:00:00 -- Using DATEADD for date ranges: SELECT * FROM orders WHERE order_date >= DATEADD(MONTH, -1, GETDATE()); -- Last 30 days of orders A close relative is NOW(), which returns the current date and time as a timestamp. A close relative is CURDATE(), which returns the current date without time. A close relative is DATE(), which extracts the date part from a datetime expression.