Age

  • Thread starter Thread starter Emma
  • Start date Start date
E

Emma

Can somebody help me with the code for a persons age based on a date given?
 
Can somebody help me with the code for a persons age based on a date given?
On a Date Given? Given how? Stored in a field on a table?

In a query:
Age: DateDiff("yyyy",[DOB],[DateGiven])-IIf(Format([DOB],
"mmdd")>Format([DateGiven],"mmdd"),1,0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],[DateGiven])-IIf(Format([DOB],
"mmdd")>Format([DateGiven],"mmdd"),1,0)

Where [DOB] is the birthdate field and [DateGiven] contains the date
to compute the age to.

As of the current date?

In a query:
Age: DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

You do know, I hope, that this Age computation should NOT be stored
in any table. Just compute it and display it on a form or report, as
needed.
 
Thanks Fred works great!

fredg said:
Can somebody help me with the code for a persons age based on a date given?
On a Date Given? Given how? Stored in a field on a table?

In a query:
Age: DateDiff("yyyy",[DOB],[DateGiven])-IIf(Format([DOB],
"mmdd")>Format([DateGiven],"mmdd"),1,0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],[DateGiven])-IIf(Format([DOB],
"mmdd")>Format([DateGiven],"mmdd"),1,0)

Where [DOB] is the birthdate field and [DateGiven] contains the date
to compute the age to.

As of the current date?

In a query:
Age: DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],
"mmdd")>Format(Date(),"mmdd"),1,0)

You do know, I hope, that this Age computation should NOT be stored
in any table. Just compute it and display it on a form or report, as
needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top