SQL Server > Date Time related

Get difference between two dates in SQL Server

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

Passing first parameter as different interval values, we can get year, month and days. Here, the SQL query will return difference of two dates in year, month an days respectively.

 Views: 10613 | Post Order: 76



Write for us






Hosting Recommendations