The return value is Years: ?? Months: ?? Days: ?? with the prober values instead of '??'
This handles leap years by using the built in functions of VB.
Public Function DateDiff2(ByVal d1 As Date, ByVal d2 As Date) As String
Dim d3 As Date, nDays As Integer
Dim d1Day As Integer, nDayStart As Integer
Dim nYears As Integer, d1Mon As Integer, MonLast As Integer, nn As Integer, nMon As Integer, d1Year As Integer
MonLast = d1Mon
Do While d2 > d1
d1 = d1 + 1
nn = nn + 1
nDays = nDays + 1
If (Day(d1) = d1Day) And Month(d1) <> MonLast Then
nMon = nMon + 1
nDays = 0
MonLast = Month(d1)
If nMon = 12 Then
nMon = 0
nYears = nYears + 1
End If
End If
Loop
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.