Calculating a DOB into Years

E

Eric

On one of the forms in my data back there is Patient information, Patient
Name, MRN, and then Date of Birth. I added a field on the form with the
following:
=Date()-[Date of Birth]/365
I was hoping this would show the age of the patient in years (works similar
in Excel) however when I do that it returns a date and time even when I
change the format to General or Standard number. Any suggestions.
 
S

scubadiver

Spreadsheet mentality is a bit lazy.

try this in a query:

Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

or in a form:

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

James A. Fortune

Eric said:
On one of the forms in my data back there is Patient information, Patient
Name, MRN, and then Date of Birth. I added a field on the form with the
following:
=Date()-[Date of Birth]/365
I was hoping this would show the age of the patient in years (works similar
in Excel) however when I do that it returns a date and time even when I
change the format to General or Standard number. Any suggestions.

My favorite:

In a query:

SELECT Int(Format(Date(), "yyyy.mmdd") - Format([Date of Birth],
"yyyy.mmdd")) AS Age FROM MyTable;

In VBA:

Dim intAge As Integer
Dim dtBirthDate As Date

dtBirthDate = #5/7/88#
intAge = Int(Format(Date(), "yyyy.mmdd") - Format(dtBirthDate, "yyyy.mmdd"))
MsgBox intAge

=> 20

Note that the .mmdd fractions are not true fractions of years, but their
relative order remains the same as the relative order of the true
fractions of years. Thus the poset (partially ordered set) will produce
exactly the same results as the true year fraction when detecting when
the age will increment.

James A. Fortune
(e-mail address removed)
 

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

Top