DATEADD Function: Add Time Intervals to Dates

The DATEADD function is used to add a specified time interval to a date. Its basic syntax is as follows:

DATEADD(datepart, number, date)

Among them, the datepart parameter specifies the time interval to be added to the date (such as year, month, day, etc.); the number parameter specifies the amount to be added; the date parameter specifies the initial date to which the time interval is to be added.

For example, if you want to add 30 days to the current date, you can use the following query:

SELECT DATEADD(day, 30, GETDATE())

This will return the date that is 30 days ahead of the current date.常用的datepart 参数包括:

  1. year: year
  2. month: a unit of time equal to approximately 30 days in the calendar
  3. day: sky
  4. hour: an hour
  5. minute: a unit of time equal to sixty seconds
  6. second: a unit of time equal to 1/60th of a minute

The DATEADD function makes it easy to perform addition and subtraction operations on dates, to meet common time processing needs.

bannerAds