How to find the difference between two given dates in SQL Server?

Last updated:11/22/2021 11:09:17 PM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

DATEDIFF():

    SQL DATEDIFF() function is used to find the difference between two given dates in term of year, month or day.

Example:    

Find the different between two date in Year.

    SELECT DATEDIFF(YEAR,'2011/12/15','2013/05/25');

 Output:         2

      Find the different between two date in Month.

SELECT DATEDIFF(MONTH,'2011/12/15','2013/05/25');

Output:     17

Find the different between two date in Day.

SELECT DATEDIFF(DAY,'2011/12/15','2013/05/25');

Output:    527

Answer