AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL DATEADD Function |
|
SQL > SQL Date Functions >
Dateadd Function
The DATEADD function is used to add an interval to a date. This function is available in SQL Server. DATEADD(datepart, number, expression) adds a specified integer interval to a date or datetime value in SQL Server. Use a negative number to subtract time. The result has the same data type as the input expression.
SyntaxThe syntax for the DATEADD function is as follows: where the data type of <expression> is some type of date, time, or datetime. <number> is an integer (can be positive or negative). <datepart> can be one of the following:
The result returned has the same data type as <expression>. ExamplesBelow we show several examples of the output from applying the DATEADD function. Example 1The SQL statement, produces the following result: '2000-01-15 00:05:00.000'
In this example, we are adding 10 days to the original datetime. Example 2The SQL statement, produces the following result: '2000-01-04 14:05:00.000'
In this example, we are subtracting 10 hours from the original datetime. Example 3The SQL statement, produces the following result: '2000-02-15 00:05:00.000'
In this example, we use the abbreviation for "month" to add one month to the original datetime. List of SQL Date Functions
Frequently Asked QuestionsWhat does the SQL DATEADD function do?DATEADD adds (or subtracts when the number is negative) a specified time interval to a date or datetime value. It is available in SQL Server and lets you work with any granularity from nanoseconds to years. What is the syntax for DATEADD?
Can DATEADD subtract dates?Yes. Pass a negative number to subtract the interval. For example, What data type does DATEADD return?DATEADD returns a value with the same data type as the |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.