What is the function of the SQL DATEDIFF function?

The DATEDIFF function calculates the difference between two dates. It returns an integer representing the number of units between the two dates, which can be in terms of days, weeks, months, quarters, or years.

Syntax:
DATEDIFF(unit, start_date, end_date)

Parameters:

  1. ‘unit’ indicates the unit of measurement for the difference in dates. It can be one of the following: day, week, month, quarter, or year.
  2. start date: the date when something begins.
  3. End date: the date when something is finished.

The result of DATEDIFF(day, ‘2022-01-01’, ‘2022-01-10’) is 9, indicating a 9-day difference between the start and end date.

bannerAds