From: Laura on
I'm doing end of term reports for pupils in a school whereby each report
needs to show the age of the pupil on a given date in YEARS and MONTHS (not
a fraction of the year). In other words, 10 yrs and 3 months, (not 10.25).
I've managed to use a function called Diff2Dates Author: � Copyright 2001
Pacific Database Pty Limited Graham R Seach MCP MVP gseach(a)pacificdb.com.au
to display the pupils age in years and months fine, but I ALSO need to show
the Average Age of the Class in Years and Months.

Simply adding up the results of the Function above and dividing by the
number of children did not work accurately, nor did using AVG as the result
was a fraction of the year and not the exact average of months.

Does anyone have a function for calculating the Average Age in Years and
Months, please?

Thanks
Laura


From: KARL DEWEY on
Why not average and then apply the function called Diff2Dates?

--
Build a little, test a little.


"Laura" wrote:

> I'm doing end of term reports for pupils in a school whereby each report
> needs to show the age of the pupil on a given date in YEARS and MONTHS (not
> a fraction of the year). In other words, 10 yrs and 3 months, (not 10.25).
> I've managed to use a function called Diff2Dates Author: © Copyright 2001
> Pacific Database Pty Limited Graham R Seach MCP MVP gseach(a)pacificdb.com.au
> to display the pupils age in years and months fine, but I ALSO need to show
> the Average Age of the Class in Years and Months.
>
> Simply adding up the results of the Function above and dividing by the
> number of children did not work accurately, nor did using AVG as the result
> was a fraction of the year and not the exact average of months.
>
> Does anyone have a function for calculating the Average Age in Years and
> Months, please?
>
> Thanks
> Laura
>
>
> .
>
From: KenSheridan via AccessMonster.com on
Laura:

You can get the total number of months of each pupil's Age with:

DateDiff("m",[DoB],Date())+IIf(Day([DoB])>=Day(Date()),1,0)

So in a query you can average that with:

AvgAgeInMonths: AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))

You can of course substitute a literal date for the Date() function if you
want the age on a specific date rather than the current date.

You can convert that to years and month with a combination of integer
division and the Mod operator. You can do it in the query by repeating the
expression:

AvgAge: AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))\12 & "
yrs and " & AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0)) Mod
12 & " months"

or you do the same in a footer of a report which lists all the pupils, in an
unbound text box, using the same expression as the ControlSource:

=Avg(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))\12 & " yrs and
" & Avg(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0)) Mod 12 & "
months"

Ken Sheridan
Stafford, England

Laura wrote:
>I'm doing end of term reports for pupils in a school whereby each report
>needs to show the age of the pupil on a given date in YEARS and MONTHS (not
>a fraction of the year). In other words, 10 yrs and 3 months, (not 10.25).
>I've managed to use a function called Diff2Dates Author: © Copyright 2001
>Pacific Database Pty Limited Graham R Seach MCP MVP gseach(a)pacificdb.com.au
>to display the pupils age in years and months fine, but I ALSO need to show
>the Average Age of the Class in Years and Months.
>
>Simply adding up the results of the Function above and dividing by the
>number of children did not work accurately, nor did using AVG as the result
>was a fraction of the year and not the exact average of months.
>
>Does anyone have a function for calculating the Average Age in Years and
>Months, please?
>
>Thanks
>Laura

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/201002/1

From: KenSheridan via AccessMonster.com on
Correction. First expression should have been:

DateDiff("m",[DoB],Date())+IIf(Day([DoB])>Day(Date()),1,0)

KenSheridan
Stafford, England

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/201002/1

From: Laura on
Ken, thanks for replying so quickly, it's so helpful.
Your formula works - thank you so much. I got slightly confused - did you
mean a minus or plus sign before the IIF? I'm not sure of the significance.

_________________________________________________
DateDiff("m",[DoB],Date())+IIf(Day([DoB])>Day(Date()),1,0)
AvgAgeInMonths:
AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))
_________________________________________________

Either seems to work. I used it in the Query Builder window and can program
it to "Enter Date" so that the school can use it for each of the 3 terms of
the year to then mailmerge into the School Reports.

Many thanks again.
Laura
Wimbledon
London
UK



"KenSheridan via AccessMonster.com" <u51882(a)uwe> wrote
Correction. First expression should have been:
DateDiff("m",[DoB],Date())+IIf(Day([DoB])>Day(Date()),1,0)


"KenSheridan via AccessMonster.com" <u51882(a)uwe> wrote in message
news:a389039a04f4e(a)uwe...
> Laura:
>
> You can get the total number of months of each pupil's Age with:
>
> DateDiff("m",[DoB],Date())+IIf(Day([DoB])>=Day(Date()),1,0)
>
> So in a query you can average that with:
>
> AvgAgeInMonths:
> AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))
>
> You can of course substitute a literal date for the Date() function if you
> want the age on a specific date rather than the current date.
>
> You can convert that to years and month with a combination of integer
> division and the Mod operator. You can do it in the query by repeating
> the
> expression:
>
> AvgAge: AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))\12 &
> "
> yrs and " & AVG(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))
> Mod
> 12 & " months"
>
> or you do the same in a footer of a report which lists all the pupils, in
> an
> unbound text box, using the same expression as the ControlSource:
>
> =Avg(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0))\12 & " yrs
> and
> " & Avg(DateDiff("m",[DoB],Date())-IIf(Day(DoB)>Day(Date()),1,0)) Mod 12 &
> "
> months"
>
> Ken Sheridan
> Stafford, England
>
> Laura wrote:
>>I'm doing end of term reports for pupils in a school whereby each report
>>needs to show the age of the pupil on a given date in YEARS and MONTHS
>>(not
>>a fraction of the year). In other words, 10 yrs and 3 months, (not 10.25).
>>I've managed to use a function called Diff2Dates Author: � Copyright
>>2001
>>Pacific Database Pty Limited Graham R Seach MCP MVP
>>gseach(a)pacificdb.com.au
>>to display the pupils age in years and months fine, but I ALSO need to
>>show
>>the Average Age of the Class in Years and Months.
>>
>>Simply adding up the results of the Function above and dividing by the
>>number of children did not work accurately, nor did using AVG as the
>>result
>>was a fraction of the year and not the exact average of months.
>>
>>Does anyone have a function for calculating the Average Age in Years and
>>Months, please?
>>
>>Thanks
>>Laura
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/201002/1
>