Take a look at the below code:
Dim date_1, date_2, l, r(2)
date_1 = "01-09-2014"
date_2 = "08-10-2016"
l = SetLocale(2057) ' UK
Delta 0, Array("yyyy", "m", "d"), Array("years", "months", "days"), r, CDate(date_1), CDate(date_2), False
SetLocale l
MsgBox Join(r, ", ") ' 2 years, 1 months, 7 days
Sub Delta(i, t, n, r, d1, d2, c)
Dim q, d
q = DateDiff(t(i), d1, d2)
If UBound(t) > i Then
Do
d = DateAdd(t(i), q, d1)
Delta i + 1, t, n, r, d, d2, c
If c Then Exit Do
q = q - 1
Loop
End If
c = q >= 0
r(i) = q & " " & n(i)
End Sub
You even can set the date and time and compute difference up to second:
Dim date_1, date_2, l, r(5)
date_1 = "01-09-2014 10:55:30"
date_2 = "08-10-2016 15:45:10"
l = SetLocale(2057) ' UK
Delta 0, Array("yyyy", "m", "d", "h", "n", "s"), Array("years", "months", "days", "hours", "minutes", "seconds"), r, CDate(date_1), CDate(date_2), False
SetLocale l
MsgBox Join(r, ", ") ' 2 years, 1 months, 7 days, 4 hours, 49 minutes, 40 seconds
Sub Delta(i, t, n, r, d1, d2, c)
Dim q, d
q = DateDiff(t(i), d1, d2)
If UBound(t) > i Then
Do
d = DateAdd(t(i), q, d1)
Delta i + 1, t, n, r, d, d2, c
If c Then Exit Do
q = q - 1
Loop
End If
c = q >= 0
r(i) = q & " " & n(i)
End Sub