SQL Server Date Function DATEADD()

www.igift‮aedi‬.com

The DATEADD() function in SQL Server is used to add a specified number of intervals (such as days, months, or years) to a date or datetime value. It takes three arguments: the interval type to add, the number of intervals to add, and the date or datetime value to add the intervals to.

The syntax of the DATEADD() function is as follows:

DATEADD(interval, number, date)

Here's an example of how to use the DATEADD() function in a SQL query to add 30 days to a given date:

SELECT DATEADD(day, 30, '2022-02-28');

This query will return the date "2022-03-30", which is the result of adding 30 days to the date "2022-02-28".

In this example, the interval is "day" since we want to add days to the date. The number is 30, which is the number of days to add. The date is "2022-02-28", which is the date to add the days to.

Note that the DATEADD() function is specific to SQL Server and the syntax and date format it supports may vary slightly depending on the system. Additionally, the DATEADD() function can be used to add intervals other than days, such as months, years, or even milliseconds, by using different interval types.