|
Posted by IchBin on 09/18/06 21:12
ameshkin wrote:
> What I am trying to do, is...
>
> Find users in a database between two ages.
>
> $minage
> $maxage
>
> The birthdays of the users are in the database in this format
> 01-30-1980
>
> Now this function takes a birthday in this format 1980-01-30 and
> returns the age
>
> function birthday ($birthday)
> {
> list($year,$month,$day) = explode("-",$birthday);
> $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--;
> return $year_diff;
> }
>
> But what I need to do, is somehow only show the results from the
> database where the birthday is in between two different ages.
>
> How do I do this. My brain hurts enough already from writing the
> function above. Can anyone help?
>
Friend!, if you have to cross post make sure you have all of the
newsgroups in to TO: statement before you send it. It stops you from
wasting other peoples time not knowing someone else had resolved your
problem already in another group!
First off, you should keep the date in the database the default format
'yyyy-MM-DD'.
I am not handling leap years but gives you a start. You may want to
build a procedure to do all of this and include leap year:
$minAge = 24;
$maxAge = 54;
SELECT
LASTNAME,
FIRSTNAME,
ROUND(DATEDIFF(CURDATE(),birthday)/365) AS 'numberOfYears',
birthday
FROM table
WHERE
ROUND(DATEDIFF(CURDATE(),birthday)/365) <= $maxAge AND
ROUND(DATEDIFF(CURDATE(),birthday)/365) >= $minAge;
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Navigation:
[Reply to this message]
|