Страница 1 из 1

Расчёт возраста по дате рождения

Добавлено: 2014-01-23 11:00:15
deepblue
Код функции

Код: Выделить всё

function age($bdate) {
	$entbyear = substr($bdate,0,4);
	$entbmonth = substr($bdate,5,2);
	$entbmonth = $entbmonth - 1;
	$entbday = substr($bdate,8,2);
	$entbday = $entbday - 1;
	$entAge = (date("Y")-$entbyear)-1;
	if((date("n") > $entbmonth && date("n") < $entbmonth + 2 && date("j") > $entbday) || (date("n") > $entbmonth + 1)) {
		$entAge = $entAge + 1;
	}
	return $entAge;
}
Получить возраст можно так:

Код: Выделить всё

$myage = age("1982-01-01");