how to calculate someones age

  • Thread starter Thread starter Dave Smith
  • Start date Start date
D

Dave Smith

hi again,
i have a clients details form which i want to enter their
birthdate into, i want the form to calculate their age & possibly save that
age to the clients details table (i want to run a report based on age later)
at the moment i have a bound text box to enter birthdate into & a bound text
box for the age.

thanking you in advance

Dave Smith
 
You need to use datediff

? datediff("yyyy",#05/05/1968#,now)

= 37 (at the moment)

I would suggest not saving the age in the database, because it can be
calculated at any point in time and it will become incorrect by next year
sometime, also the above is just subtracting one year from the next, for a
more accurate you might have to calculate on days

? datediff("d",#20/05/1968#,now)

and then work out years with 365 days and years with 366 days something like

1461 days every 4 years.
 
Both calculations shown can be inaccurate. As an extreme example, on January
1st, the first approach would show that a baby born the previous day is 1
year old.

The "trick" is to determine whether the birthday has already taken place
that year or not, and adjust accordingly.

= DateDiff("yyyy", [DOB], Date()) - IIf(Format(Date(), "mmdd") <
Format([DOB], "mmdd"), 1, 0)

Age should DEFINITELY not be stored in the table: create a query that uses
the formula above, and use the query wherever you would otherwise have used
the table.
 
That i'll do it.....

--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Douglas J Steele said:
Both calculations shown can be inaccurate. As an extreme example, on
January
1st, the first approach would show that a baby born the previous day is 1
year old.

The "trick" is to determine whether the birthday has already taken place
that year or not, and adjust accordingly.

= DateDiff("yyyy", [DOB], Date()) - IIf(Format(Date(), "mmdd") <
Format([DOB], "mmdd"), 1, 0)

Age should DEFINITELY not be stored in the table: create a query that uses
the formula above, and use the query wherever you would otherwise have
used
the table.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Alex White MCDBA MCSE said:
You need to use datediff

? datediff("yyyy",#05/05/1968#,now)

= 37 (at the moment)

I would suggest not saving the age in the database, because it can be
calculated at any point in time and it will become incorrect by next year
sometime, also the above is just subtracting one year from the next, for
a
more accurate you might have to calculate on days

? datediff("d",#20/05/1968#,now)

and then work out years with 365 days and years with 366 days something like

1461 days every 4 years.

--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk
 
Back
Top