OutbackInvestments
06-09-2000, 05:50 AM
Hi. I know this is probably a simple question, and it probably has a simple answer, but I have to ask anyway. How do you make it so that you enter in a Birthdate, (dd,mm,yyyy) and have it calculate an age from that with Date$(). I have got a quasi-result with DateDiff, but It doesnt take into account the day and month (e.g, birth day in October, now its june. Says age 18)
Can anyone help?
Thanks.
Matt Leidemer
06-09-2000, 06:40 AM
Simplest way is as follows (in pseudocode):
set TEMP = current_year - birth_year
if (current_month < birth_month) or (current_month = birth_month and current_day < birth_day) then set TEMP = TEMP - 1
set AGE = TEMP
Using me as an example (DOB 8/30/80):
TEMP = 2000 - 1980 = 20
current month (June) is less than (before) birth month (August) so TEMP = TEMP - 1 = 19
I'm not a hotshot Access programmer, so you'll need to convert this into Access/VB code, but this is the simplest algorithm for it.
- Matt
[This message has been edited by Matt Leidemer (edited 06-09-2000).]
[This message has been edited by Matt Leidemer (edited 06-09-2000).]
R. Hicks
06-09-2000, 07:10 AM
Try this Function:
Public Function fGetAge(BDate As Date) As Integer
fGetAge = DateDiff("yyyy", BDate, Date) _
+ (Date < DateSerial(Year(Date), Month(BDate), Day(BDate)))
End Function
HTH
RDH