Age from date

  • Thread starter Thread starter Poppy
  • Start date Start date
P

Poppy

I need to be able to extract someones age from a date but
if the person is under 1 month old show it in days.

If the person is under a year and over a month it must
show months and days else years months and days.

This must be acurate but I cannot figure it out.

Any ideas ?

TIA
 
You have to calculate the difference in days first:

Dim dtCurrent, dtBirthdate As Date
Dim intDays As Integer

dtCurrent = Date
dtBirthdate = CDate(Me.txtBirthdate.Value)

intDays = DateDiff("d", dtBirthdate, dtCurrent)

If intDays / 365 < 1 Then
MsgBox intDays
Else
MsgBox intDays / 365
End If

The only problem here is that you'd have to figure out how
to handle the decimal. You could take intDays / months in
a year and days in a year to get exactly the months, days,
and years that person has been living. I figured you'd be
able to get the idea from the code above. Let me know if
you need more help.

Hope this helps,
Crystal
 
Back
Top