<div dir="ltr">Calculate the current age of all users. Then sum and divide by the total amount of users. For a less accurate solution you could suffice by calculating the age just by averaging over all the years of birth, and subtracting 0.25. We assume then that birthdays are spread out uniformly, and thus subtraction of 0.25 is necessary to compensate for the birthdays in Oct, Nov, and Dec that still haven&#39;t passed yet.<br>
<br>Problem is that the Profile module saves its date field as a serialized array, so you have to do all the work in PHP in stead of directly on the database. <br><br>Because I use the Birthdays module (which stores its birthdays as datetime values), I can directly calculate it from the database using the below methods.<br>
<div style="margin-left: 40px;">// Short, inaccurate method<br>
avg(year(now() - year(birthday)) - 0.25 = 24,2 years old<br><br>// Longer, but more accurate method.<br>
avg((year(now()) - year(birthday))+(DAYOFYEAR(now()) &gt; DAYOFYEAR(birthday))) = 24.2 years old<br></div><br>In PHP you want something like this:<br>&lt;?php <br>$result = db_query(&quot;SELECT value FROM {profile_values} WHERE fid = %d&quot;, $profile_field_id_of_date_field);<br>
$i = 0;<br>$sum = 0;<br>while ($row = db_fetch_object($result)) {<br>&nbsp; $dob = unserialize($row-&gt;value);<br>&nbsp; if(is_array($dob)) {<br>&nbsp;&nbsp;&nbsp; extract($dob);<br>&nbsp; }<br><br>&nbsp; if ($day &amp;&amp; $month &amp;&amp; $year) {<br>
&nbsp;&nbsp;&nbsp; // Current year - birthday_year - (1 if birthday hasn&#39;t been yet)<br>&nbsp;&nbsp;&nbsp; $age = (date(&#39;Y&#39;) - $year) - (date(&#39;nd&#39;) &lt; $month . str_pad($day, 2, 0, STR_PAD_LEFT));<br>&nbsp;&nbsp;&nbsp; $sum += $age;<br>&nbsp;&nbsp;&nbsp; $i++;<br>
&nbsp; }<br>}<br>$average_age = $sum / $i;<br>?&gt;<br><div> <br><div class="gmail_quote">On Wed, Oct 8, 2008 at 3:48 PM, Rohan Smith <span dir="ltr">&lt;<a href="mailto:rohanasmith@gmail.com">rohanasmith@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>how could i calculate average age of my members using a profile date_of_birth date field?</div>

<br>--<br>
[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br></blockquote></div><br></div></div>