# Thread: Age Convert to Years only

1. Registered User
Join Date
May 2014
Posts
14

## Unanswered: Age Convert to Years only

Out of curiosity just for learning if I wanted this particular code which works perfectly to generate Age simple in years i.e. 56. What changes would I need to change? This is a public function I currently use. I simply want it to give me a numeric age only. Rather than this which current code generates the following example: 93 years, 3 months and 30 days. I want to compare and contrast both and see what is different I learn easier that way. Thanks everyone for your help.

Public Function FindAge(DOB As Date, CalcDate As Date) As String
Dim intYears As Integer, intMonths As Integer, intDays As Integer
intMonths = DateDiff("m", DOB, CalcDate)
intDays = DateDiff("d", DateAdd("m", intMonths, DOB), CalcDate)
If intDays < 0 Then
intMonths = intMonths - 1
intDays = DateDiff("d", DateAdd("m", intMonths, DOB), CalcDate)
End If
intYears = intMonths \ 12
intMonths = intMonths Mod 12

FindAge = intYears & " year" & IIf(intYears = 1, "", "s") _
& ", " & intMonths & " month" & IIf(intMonths = 1, "", "s") _
& " and " & intDays & " day" & IIf(intDays = 1, "", "s")
End Function

2. Moderator
Join Date
Jun 2005
Location
Richmond, Virginia USA
Posts
2,764
To get an actual age in years only is much simpler! There are several formulas for this, but here's one I've used for years. In getting age in years the only concern is whether or not a person has celebrated their birthday for the current year, by the date you're comparing their DOB against, in this example CalcDate:

Code:
`FindAge = DateDiff("yyyy", [DOB], CalcDate) + Int(Format(CalcDate, "mmdd") < Format([DOB], "mmdd"))`

Linq ;0)>