Updated on Kisan Patel
This tutorial will show you how to get the difference between two dates in SQL Server?
To get the difference between two dates, we can use DATEDIFF
function.
SELECT DATEDIFF(YY, '01/24/1977', GETDATE()) AgeInYears, DATEDIFF(MM, '01/24/1977', GETDATE()) AgeInMonths, DATEDIFF(DD, '01/24/1977', GETDATE()) AgeInDays
Here, we have pass first parameter as different interval values. So, we can get year, month and days. Here, the SQL query will return difference of two dates in year, month an days respectively.