note 59075 deleted from function.date by nlopess
| From: | nlopess@php.net | Date: | Fri, 25 Nov 2005 19:23:52 +0000 |
| Subject: | note 59075 deleted from function.date by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-99103@lists.php.net to get a copy of this message | ||
Note Submitter: ian at roofchop dot com
----
I find this way to be the best, for me, to work out a users age in PHP
<?php
// Get Birth Date Info
$doby=$_POST['year'];
$dobm=$_POST['month'];
$dobd=$_POST['day'];
// Explode Todays Date
$tody=gmdate('Y');
$todm=gmdate('m');
$todd=gmdate('d');
// Work Out Approx Age
$approx_age=($tody-$doby);
// Work Out Exact Age
if ($todm>$dobm) {
$age=$approx_age;
} else if ($todm<$dobm) {
$age=$approx_age-1;
} else {
if ($todd>=$dobd) {
$age=$approx_age;
} else {
$age=$approx_age-1;
}
}
?>