ms sql dateadd is the Transact-SQL function for date-time arithmetic, adding an integer interval to a specified datepart (year, month, day, etc.) and returning the computed datetime value, commonly used in SQL Server 2017-2022.
-- Add 10 days to current date
SELECT DATEADD(day, 10, GETDATE()) AS FutureDate;
ms sql dateadd Syntax Reference
The canonical syntax for DATEADD in T-SQL (Microsoft SQL Server, Azure SQL Database) is:
DATEADD ( datepart , number , date )
Parameters:
- datepart — the part of date to which
numberis added (e.g.,year,month,day,hour,minute,second,millisecond,microsecond,nanosecond). - number — an expression that resolves to a
bigint; value to add (positive for future, negative for past). - date — an expression that evaluates to a date/time value (string literal, column, variable, or function like
GETDATE()).
Return type depends on the input date data type. If date is a string literal, output is datetime; if datetime2, output is datetime2.
-- Subtract 3 months from a specific date
SELECT DATEADD(month, -3, '2025-06-15') AS PastDate;
-- Add 1 year and 2 months (single levels only)
SELECT DATEADD(year, 1, DATEADD(month, 2, GETDATE()));
ms sql dateadd Rapid Reference Cheat Sheet
| Action | CLI Command (T-SQL) | Datepart | Impact / Result |
|---|---|---|---|
| Add 5 years | SELECT DATEADD(year, 5, GETDATE()); |
year / yy / yyyy |
Returns date + 5 years; handles leap years automatically. |
| Add 30 days | SELECT DATEADD(day, 30, '2025-01-15'); |
day / dd / d |
Adds 30 calendar days while respecting month boundaries. |
| Add 2 hours | SELECT DATEADD(hour, 2, SYSDATETIME()); |
hour / hh |
Adds 2 hours to a high-precision datetime2 value. |
| Add 100 milliseconds | SELECT DATEADD(millisecond, 100, GETDATE()); |
millisecond / ms |
Adds fractional seconds; limited to 3 digits for datetime. |
| Add 1 microsecond | SELECT DATEADD(microsecond, 1, CAST('2024-01-01 13:10:10.1111111' AS DATETIME2)); |
microsecond / mcs |
Precision beyond milliseconds requires DATETIME2; smalldatetime raises error Msg 517. |
Tested on SQL Server 2022 (16.0.1000.6).
Advanced Implementation & Parameters
Datepart Argument (datepart)
SQL Server recognizes both full name and abbreviations. Full list:
- year (
yy,yyyy) - quarter (
qq,q) - month (
mm,m) - dayofyear (
dy,y) — adds days to the date (same asday) but logical grouping differs. - day (
dd,d) - week (
wk,ww) — increments by 7-day intervals. - weekday (
dw,w) — adds number of weekdays (Sunday=1). - hour (
hh) - minute (
mi,n) - second (
ss,s) - millisecond (
ms) - microsecond (
mcs) — only supported whendateisdatetime2ordatetimeoffset. - nanosecond (
ns) — same restriction, fractional seconds of nanosecond precision.
Number Argument (number)
Accepts bigint; values can be negative. Fractional decimals are truncated (not rounded). For example, DATEADD(day, 2.7, '2025-01-01') adds 2 days (truncates .7). Use CAST(number AS int) if integer is guaranteed.
Date Argument (date)
Can be any expression that evaluates to a date/time type: GETDATE(), column names, string literals (e.g., '2025-06-15 14:30:00.123'), CURRENT_TIMESTAMP, SYSDATETIME(). When using string literals, implicit conversion occurs; for fractional seconds, provide enough digits to avoid truncation.
Return Types and Behavior
| Input Date Type | Return Type | Precision |
|---|---|---|
datetime |
datetime |
3.33 ms |
smalldatetime |
smalldatetime |
1 minute (seconds always :00) |
datetime2 |
datetime2 |
Up to 7 digits of fractional seconds |
datetimeoffset |
datetimeoffset |
Same as datetime2 + time zone offset |
date |
date |
No time component |
| String literal (no time) | datetime |
3.33 ms |
Fractional Seconds Precision: Adding millisecond to a datetime yields 3 decimal places. For higher precision, use datetime2. smalldatetime does not support seconds or fractional seconds — attempt causes Msg 517.
-- High-precision example from official docs
DECLARE @datetime2 AS DATETIME2 = '2024-01-01 13:10:10.1111111';
SELECT '1 millisecond', DATEADD(millisecond, 1, @datetime2)
UNION ALL
SELECT '2 milliseconds', DATEADD(millisecond, 2, @datetime2);
Error Resolution & Troubleshooting
| Error Code / Message | Root Cause | Remediation Command / Approach |
|---|---|---|
| Msg 517, Level 16, State 1 Adding a value to a ‘datetime’ column caused an overflow. |
Using smalldatetime with second or fractional second datepart (e.g., second, millisecond). |
|
| Msg 8115, Level 16, State 2 Arithmetic overflow error converting expression to data type datetime. |
Result is outside the valid range of the return type. E.g., adding 10,000 years to a datetime (range 1753-9999). |
|
| Implicit conversion error Conversion failed when converting date and/or time from character string. |
String literal for date is not a recognized format (e.g., ’31/12/2025′ in non-British session). |
|
| NULL result (no error, but result is NULL) | When date argument is NULL. |
Ensure source column is not NULL; use ISNULL() with a default. |
Also note that DATEADD does not accept user-defined data types or XML; always pass a date/time type.
Production-Grade Implementation
- Use explicit datepart names (e.g.,
dayinstead ofdd) to improve readability and avoid ambiguity. Abbreviated forms are supported but full names are clearer. - Avoid adding days via simple addition (
date + 360) — this relies on internaldatetimeinteger representation and breaks fordatetime2. Always useDATEADDfor clarity and portability. - For large intervals, chain multiple
DATEADDcalls rather than converting to a single component (e.g., 365 days = 1 year + 0 days; useDATEADD(year, 1, DATEADD(day, 0, @date))). - Use
SYSDATETIME()instead ofGETDATE()when working with fractional seconds, becauseGETDATE()returnsdatetimewith 3 ms precision.SYSDATETIME()returnsdatetime2(7). - Handle time zone offset with
datetimeoffset:DATEADDworks on the date/time component only; the offset remains unchanged. For shifting time zones, useSWITCHOFFSET. - Performance:
DATEADDis deterministic and sargable when used in WHERE clauses. For large datasets, avoid wrapping a column inDATEADDon the field — instead compute the offset on the constant side (e.g.,WHERE OrderDate > DATEADD(day, -30, GETDATE())).
Frequently Asked Questions
What is the difference between DATEADD and DATEDIFF in SQL Server?
Answer: DATEADD returns a new datetime by adding an interval to a date; DATEDIFF returns the integer count of intervals between two dates. DATEADD(
When should I use DATEADD with a negative number?
Answer: Use a negative integer to subtract intervals from a date. This eliminates the need for separate subtraction logic. It works for any datepart (month, year, hour, etc.) and is common for rolling window queries or expiration checks.
How do I fix “Argument data type datetime is invalid for argument 2 of dateadd function”?
Answer: Ensure argument 2 (the number to add) is an explicit integer, not a datetime or string. Example: SELECT DATEADD(day, CAST('7' AS int), GETDATE()); The error occurs when
Does DATEADD work on Azure SQL Database and Azure SQL Managed Instance?
Answer: Yes, DATEADD is fully supported across all SQL Server versions (2008+) and all Azure SQL services – including Azure SQL DB, Managed Instance, and Azure Synapse serverless SQL pool (limited to microsecond precision). The syntax and datepart list are identical. No compatibility flags needed.
What is the fastest way to add days to a date in SQL Server?
Answer: Use DATEADD(day, , ) directly in a single scalar expression. For bulk operations, apply DATEADD in a set-based UPDATE or SELECT without cursors: UPDATE Orders SET ShipDate = DATEADD(day, 3, OrderDate) WHERE Status = 'Pending'; This minimizes CPU overhead compared to row-by-row operations.

Command Line Expert & Software Engineer
Welcome! I’m Thomas Heinrich, a software engineer and system administrator with a deep passion for the Command Line Interface (CLI). With years of experience navigating the terminal, building backend architectures, and automating server deployments, I created this space to share practical, real-world terminal knowledge.
Whether you are a beginner taking your first steps in a Linux environment or a seasoned DevOps engineer looking to optimize your deployment scripts, you will find actionable solutions here. My goal is to help you ditch the mouse, speed up your workflow, and harness the full power of the command line.