' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Function age(cpr6 As String) As Integer
    Dim yy, mm, dd, res As Integer
    yy = CInt(Mid(cpr6, 5, 2))
    mm = CInt(Mid(cpr6, 3, 2))
    dd = CInt(Mid(cpr6, 1, 2))
    res = (DatePart("yyyy", Now()) - yy) Mod 100
    If (DatePart("m", Now()) < mm) Or ((DatePart("m", Now()) = mm) And (DatePart("d", Now()) < dd)) Then res = res - 1
    age = res
End Function

Function test_age()
    MsgBox CStr(age("051084"))
    MsgBox CStr(age("240206"))
    MsgBox CStr(age("250206"))
    MsgBox CStr(age("260206"))
End Function
