Code:
Function GetYears(ByVal DateFm As Long, ByVal DateTo As Long) As Double
Dim Leap004 As Long
Dim Leap100 As Long
Dim Leap400 As Long
Dim LeapYears As Long
Dim SmblYears As Long
Dim Leap As Long
Dim Smbl As Long
Dim LeapFm As Long
Dim SmblFm As Long
Dim inDate As Long
Dim yy As Integer
'Years between 102 And 9999
If DateFm < DateSerial(102, 1, 1) Or _
DateTo < DateSerial(102, 1, 1) Then Exit Function
If DateFm > DateTo Then
inDate = DateFm
DateFm = DateTo
DateTo = inDate
End If
'------------------
DateFm = DateFm - 1
'------------------
inDate = DateFm
GoSub Calculate
LeapFm = Leap
SmblFm = Smbl
'------------------
inDate = DateTo
GoSub Calculate
Leap = Leap - LeapFm
Smbl = Smbl - SmblFm
'------------------
GetYears = (Leap / 366) + (Smbl / 365)
Exit Function
'------------------
Calculate:
yy = Year(inDate) - 1
Leap004 = Fix(yy / 4)
Leap100 = Fix(yy / 100)
Leap400 = Fix(yy / 400)
LeapYears = Leap004 - Leap100 + Leap400
SmblYears = yy - LeapYears
Leap = CLng(LeapYears * 366)
Smbl = CLng(SmblYears * 365)
' Day(DateSerial(yy + 1, 3, 0))
If Day(DateSerial(yy + 1, 3, 1) - 1) = 29 Then
Leap = Leap + (inDate - DateSerial(yy, 12, 31))
Else
Smbl = Smbl + (inDate - DateSerial(yy, 12, 31))
End If
Return
End Function