|
Posted by ameshkin on 09/18/06 20:46
Yes, thats one problem. For other reasons, teh date is in the database
as a string. When I get home, i will changbe the structure around and
see if i can just use a simple sql query to get my results.
Thanks for the help
Oli Filth wrote:
> 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.
>
> I assume from the above that you are storing birthdays in the database
> as strings. This is more trouble than it's worth. Most databases have
> a date type, and functions which allow easy comparisons, etc.
>
> MySQL, for instance, has loads:
> http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
>
>
> --
> Oli
Navigation:
[Reply to this message]
|