- date_diff: documentation ( source)
- date_create: documentation ( source)
- date: documentation ( source)
<?php
//create both dates (birthday and today).
$birthday = date_create($this->birthday);
$today = date_create(date('Y-m-d'));
//check if the dates are valid.
if (($birthday !== false && $today !== false) && ($birthday < $today)) {
return date_diff($birthday, $today)->y;
} else {
return -1;
}