Is there a simple way to calculate the difference between two dates that:
- expresses it as the number of years incl. the year fraction; and
- takes account of leap years?
For example, the difference between 1st March 2011 and 1st March 2012 is 1 year. However, if I use DATEDIFF(day,..,..) and divide by 365 I get an (undesirable) answer of 1.00274 because of the leap year.
To be clear, I need any year fraction as well (ie. not just the whole number of years). For example the difference between 1st March 2011 and 3rd March 2012 is 1.005479 (1 year + 2/365 years). The difference between 1st March 2011 and 29th February 2012 is 0.997268 (0 year + 365/366 years)
So, in summary, the output (in DECIMAL(7,6)) from the above two examples would be:
1.000000 1.005479 0.997268