[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pick next birthday


>
> I need to have a table that has (among others) a field that contains a
> birthdate. I want to select the record from the table that has todays date
> as the birthday or (if none matches today) the next upcoming birthday. What
> I want to display is this.
>
> If someone has a birthday today:
> A message about Happy Birthday and the persons age.
>
> If no birthday today:
> A message saying who's birthday is next and how old they will be.
>
> There will be NO duplicate birthdates.
>

what about this (untested!):

SELECT name,birthdate,YEAR(NOW())-YEAR(birthdate) AS age FROM people ORDER BY 
DAYOFYEAR(birthdate)-DAYOFYEAR(NOW()) LIMIT 1;

I hope it helps!

Jan

-- 
---------------------------------------------------------------------
Please check "http://www.mysql.com/documentation/manual.php"; before
posting. To request this thread, e-mail mysql-thread60376@xxxxxxxxxxxxxxx

To unsubscribe, send a message to:
    <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>

If you have a broken mail client that cannot send a message to
the above address (Microsoft Outlook), you can use:
    http://lists.mysql.com/php/unsubscribe.php



This mailing list archive is a service of Copilot Consulting.