This function needs DateOne to be earlier than DateTwo, I used this code elsewhere, but it could just as easily be incorporated in the Function:

VB Code:
  1. If DateTwo < DateOne Then                                     ' Make sure that first date is the smaller of the two
  2.             Dim Temp As DateTime
  3.             Temp = DateOne                                                     ' Swap them if not
  4.             DateOne = DateTwo
  5.             DateTwo = Temp
  6.         End If

And here is the main function:

VB Code:
  1. Private Function Y_M_D_Diff(ByVal DateOne As DateTime, ByVal DateTwo As DateTime) As String
  2.         Dim Year, Month, Day As Integer
  3.  
  4.         ' Function to display difference between two dates in Years, Months and Days, calling routine ensures that DateOne is always earlier than DateTwo
  5.         If DateOne <> DateTwo Then                                          ' If both dates the same then exit with zeros returned otherwise a difference of one year gets returned!!!
  6.             ' Years
  7.             If DateTwo.Year > DateOne.Year Then                       ' If year is the same in both dates, an out of range exception is thrown!!!
  8.                 Year = DateTwo.AddYears(-DateOne.Year).Year       ' Subtract DateOne years from DateTwo years to get difference
  9.             End If
  10.  
  11.             ' Months
  12.             Month = DateTwo.AddMonths(-DateOne.Month).Month         ' Subtract DateOne months from DateTwo months
  13.             If DateTwo.Month <= DateOne.Month Then                        ' Decrement year by one if DateTwo months hasn't exceeded DateOne months, i.e. not full year yet
  14.                 If Year > 0 Then Year -= 1
  15.             End If
  16.  
  17.             ' Days
  18.             Day = DateTwo.AddDays(-DateOne.Day).Day                         ' Subtract DateOne days from DateTwo days
  19.             If DateTwo.Day <= DateOne.Day Then                             ' Decrement month by one if DateTwo days hasn't exceeded DateOne days - not full month yet
  20.                 If Month > 0 Then Month -= 1
  21.             End If
  22.             If DateOne.Day = DateTwo.Day Then                        ' Avoid silliness like "1 month 31 days" instead of 2 months
  23.                 Day = 0                                                                          ' Reset days
  24.                 Month += 1                                                                   ' And increment month
  25.             End If
  26.  
  27.             ' Corrections
  28.             If Month = 12 Then                                                         ' Months value goes up to 12, and we want a maximum of 11, so:
  29.                 Month = 0                                                                     ' Reset months to zero
  30.                 Year += 1                                                                       ' And increment year
  31.             End If
  32.             If DateOne.Year = DateTwo.Year AndAlso DateOne.Month = DateOne.Month Then            ' If year and month are the same in DateOne & DateTwo then month = 12 and therefore year has been incremented
  33.                 Year = 0                                                                     ' So reset it
  34.             End If
  35.  
  36.         End If         ' DateOne <> DateTwo
  37.  
  38.         Return Year & " years, " & Month & " months, " & Day & " days"                  ' Concatenate string and return to calling routine
  39.  
  40.     End Function       ' Y_M_D_Diff