HOW DO I EXPRESS AN AGE IN YEARS AND MONTHS

G

Guest

I'm creating a database that holds data for children at the Institute of
Child Heath. It is important that the age is expressed in months as well as
years so that it is a true reflection of their age. Currently the data is
expressed in years and months separately side by side therefore a 1 year old
could be 23 months and a 14 year old, 173 months. Ideally I'd like to
express it as 1.11 or likewise. Does a format exist to express an age in this
way?

Thanks.
 
G

Guest

Here is some code that will return the Years and the months:
Dim dtDOB As Date
Dim bytTotMonths
Dim bytYrs As Byte
Dim bytMonths As Byte
dtDOB = Me.Text2
bytTotMonths = DateDiff("M", dtDOB, Now())
bytYrs = Format(bytTotMonths / 12, "00")
bytMonths = bytTotMonths - (bytYrs * 12)
Me.txtYears = bytYrs
Me.txtMonths = bytMonths

The "dtDOB = Me.Text2" line gets the Date Of Birth from a text box named
"Text2". Just substitute the name of your text box.

The two lines:
Me.txtYears = bytYrs
Me.txtMonths = bytMonths
write the value of the variable "bytYrs" to a text box named: "txtYears"
and the value of the variable "bytMonths" to a text box named: "txtMonths"

Just substitute the name your text boxes.
 
D

Dirk Goldgar

angela etheridge said:
I'm creating a database that holds data for children at the Institute
of Child Heath. It is important that the age is expressed in months
as well as years so that it is a true reflection of their age.
Currently the data is expressed in years and months separately side
by side therefore a 1 year old could be 23 months and a 14 year old,
173 months. Ideally I'd like to express it as 1.11 or likewise. Does
a format exist to express an age in this way?

You may want to look at the function posted here:

http://www.pacificdb.com.au/MVP/Code/Diff2Dates.htm

It returns a string like "14 Years 5 months". That may not be what you
want, but it could easily be modified.
 

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