- explode: documentation ( source)
- date: documentation ( source)
<?php
// todays date
$today = date("Ymd");
function age($birth_date){
list($birth_day,$birth_month,$birth_year) = explode("-",$birth_date);
$year_diff = date("Y") - $birth_year;
$month_diff = date("m") - $birth_month;
$day_diff = date("d") - $birth_day;
if ($day_diff < 0 && $month_diff==0){$year_diff--;}
if ($day_diff < 0 && $month_diff < 0){$year_diff--;}
return $year_diff;
}
//Call the age function
age('');