Okay, let's try operating on date and time data. We'll start with the relatively simple
DATEADD() function, which looks like this:
DATEADD(datepart, number, date)
DATEADD() takes the following arguments:
datepart—the part of the date that will be changed. Some common values that the datepart argument can take are:
number—the number that will be added to the given date.
date—the date being changed. This can be an actual date or a column value.
Let's suppose someone entered the wrong date for a flight and we would like our query to return a date 2 months later. We'd write:
DATEADD(month, 2, LaunchedDatetime)
In this query, two months are added to the aircraft launch date, and a new launch date is returned (two months are added). Note that the datepart argument (
month) is given as an identifier, without any quotes.