Skip to content
Advertisement

How to use DATEDIFF to return year, month and day?

How can I use DATEDIFF to return the difference between two dates in years, months and days in SQL Server 2005

How to result that: 2 year 3 month 10 day

Can anyone complete this t-sql?

Advertisement

Answer

Here’s my solution to Eric’s function:

Good call on the use of ABS to handle if the start date is after the end date.


This:

..or non-CTE using for SQL Server 2000 and prior:

…will return:

Reference: DATEDIFF

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement