DateDiff("m", [StuDOB], [DateTest]) will give you the total number of
months
between the two dates. To only get the "left over" months, you could use
DateDiff("m", [StuDOB], [DateTest]) Mod 12.
However, adding 9 as .9 can be a bit problematic. If you were only adding
values between 1 and 9, you'd divide by 10 and add it to the number of
years. However, since you can also have values of 10, 11, and 12, that
approach won't work. It would be easier if you'd accept 3.09 for 3 years,
9
months, because then you could use
=DateDiff("yyyy", [StuDOB], [DateTest]) + _
Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)
Otherwise, you'll need something like:
=DateDiff("yyyy", [StuDOB], [DateTest]) + _
IIf((DateDiff("m",[StuDOB], [DateTest]) mod 12) < 10,
Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 10, 1),
Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 100, 2))
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
CBeavers said:
I'm wanting to show 3 years 9 months as 3.9. Is that possible? I tried
the
following in the expression builder Access 2003, and it gave me an
invalid
syntax error. What am I doing wrong?
=DateDiff("yyyy", [StuDOB], [DateTest]), Round(DateDiff("m",[StuDOB],
[DateTest]) / 12., 1)
:
On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
I need to calculate the age of someone at the time that a test was
taken. I
need the age to show years and percentage of year (3.9 years old at
time
of
test).
I'm putting this formula in a form in Access 2003
My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
StuDOB = Student date of birth
DateTest = Date test was taken
I get the correct years, but I can't get the percentage in months.
Is 3.9 three years and nine months? or 3 years and 349 days (0.9
years)?
Your
phrase "percentage in months" is worrisome...
To get years and fractional years, accurate to +1 in the first decimal
place
over the span of a century (by ignoring leap years), you can use
Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)
John W. Vinson [MVP]