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. SyntaxThe syntax for the DATEADD function is as follows: DATEADD (datepart, number, expression)
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, SELECT DATEADD (day, 10, '2000-01-05 00:05:00.000');
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, SELECT DATEADD (hour, -10, '2000-01-05 00:05:00.000');
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, SELECT DATEADD (mm, 1, '2000-01-05 00:05:00.000');
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
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.