Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

DATEADD

Example

Add one year to a given date and return the resulting date.

SELECT DATEADD(year, 1‘2017/08/25’AS DateAdd;

Definition and Usage

The DATEADD() function adds a specified time or date interval to a given date and returns the resulting date.

Syntax

DATEADD(intervalnumberdate)

Parameter Values

Parameter

Description

interval

Required: Specify the time or date interval to add, using one of the following values:

  • year, yyyy, yy: Year
  • quarter, qq, q: Quarter
  • month, mm, m: Month
  • dayofyear, dy, y: Day of the year
  • day, dd, d: Day
  • week, ww, wk: Week
  • weekday, dw, w: Weekday
  • hour, hh: Hour
  • minute, mi, n: Minute
  • second, ss, s: Second
  • millisecond, ms: Millisecond

 

number

Required: Specify the number of intervals to add to the date. Use positive values to calculate dates in the future and negative values for dates in the past.

date

Required: Specify the date that will be modified by adding the specified interval.

Technical Details

Works in:

SQL Server (beginning from 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Add two months to a given date and return the resulting date.

SELECT DATEADD(month, 2‘2017/08/25’AS DateAdd;

Example

Subtract two months from a specified date and return the resulting date.

SELECT DATEADD(month, –2‘2017/08/25’AS DateAdd;

Example

Add 18 years to the dates stored in the BirthDate column, then return the updated dates.

SELECT LastName, BirthDate, DATEADD(year, 18, BirthDate) AS DateAdd FROM Employees;