Multiple choice technology

Find the function that returns the difference between two dates in terms of month.

  1. dateadd(mon,'01/01/2010',getdate())

  2. datediff(mon,'01/01/2010',getdate())

  3. datesub(mm,'01/01/2010',getdate())

  4. datediff(mm,'01/01/2010',getdate())

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The DATEDIFF function in SQL Server calculates the difference between two dates. Syntax is DATEDIFF(interval, start_date, end_date). To get month difference, use 'mm' or 'mon' as the interval. Option D is correct: DATEDIFF(mm, '01/01/2010', GETDATE()) calculates the month difference between the two dates. DATEADD adds intervals, and there's no DATESUB function.