Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014

    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. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    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:

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

    Linq ;0)>
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts