i want create average age of members. managed array of date of births , found easy way calculate birthday. don't manage combine it.
my 'date of birth' - array:
$results = array(); $dob_array = mysqli_query($conn, "select dob_array members"); while($row = mysqli_fetch_assoc($dob_array)){ $results[] = $row; }
the calculation of age:
$today = new datetime(); $birthdate = new datetime("1991-01-01"); $interval = $today->diff($birthdate); echo $interval->format('%y years');
calculation average of age-array:
$average = array_sum($array) / count($array);
might done direct sql (using timestampdiff()
, avg()
functions):
select avg(timestampdiff(year, `dob`, now())) `average` `member`;
Comments
Post a Comment