Search This Blog

Monday, July 9, 2012

DATEADD SQL Server Example

SQL Server > Built-in Functions > DATEADD

Add a number to a specified datepart of that date.

DATEADD (datepart , number , date )

datepart: is the part of date to which an integer number is added.

Example:

SELECT DATEADD(month,1, GetDate()) -- add 1 month to current day
SELECT DATEADD(day,1, GetDate()) -- add 1 month to current day
SELECT DATEADD(year,1, GetDate()) -- -- add 1 year to current day


Find last day of previous month