DATEDIFF Date Function TSQL Tutorial

Datediff is an date function and returns the count of the specified date_part boundaries crossed between twoo specified dates: start_date and end_date.

DATEDIFF Syntax:

DATEDIFF ( date_part , start_date , end_date )

DATEDIFF Example:

DECLARE @start_date datetime = '2007-02-19 22:24:10';
DECLARE @end_date datetime = '2014-02-19 22:24:10';
SELECT DATEDIFF(year, @start_date, @end_date) as Result;

Result
7

SELECT DATEDIFF(year, '2013-02-19 21:21:59', '2014-02-19 21:21:59') as Year_diff,
DATEDIFF(month, '2013-02-19 21:21:59', '2014-02-19 21:21:59') as Months_diff,
DATEDIFF(day, '2013-02-19 21:21:59', '2014-02-19 21:21:59') as Days_diff;

Year_diffMonths_diffDays_diff
112365