leeftijd
Bron:
http://www.google.nl/search?q=PHP+AGE
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?PHP
function leeftijd ($value) {
list ($year, $month, $day) = explode("-", $value);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0):
$year_diff--;
elseif ( ($month_diff == 0) && ($day_diff < 0) ):
$year_diff--;
endif;
return $year_diff;
}
?>
function leeftijd ($value) {
list ($year, $month, $day) = explode("-", $value);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0):
$year_diff--;
elseif ( ($month_diff == 0) && ($day_diff < 0) ):
$year_diff--;
endif;
return $year_diff;
}
?>
Bron:
http://www.google.nl/search?q=MySQL+AGE
Alternatief: De leeftijd via een MySQL query bepalen:
Quote:
SELECT DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(geboortedatum, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(geboortedatum, '00-%m-%d')) AS leeftijd