Noyb, being the foo Noyb is, wrote:
I have a DATE field on a mysql db that stores users birthdays (the
month and the day, the year doesn't matter). I am trying to have a
query that returns the names of those whose birthdays are today.
Currently I am returning everyones birthdays and then looping through
them doing a string comparison. Can't I do this work in the query?
Something like:
$bday_qry="SELECT user_fname, user_lname, user_bday
FROM users
WHERE DATE_FORMAT(user_bday, %m-%d)==".date("m-d");
What's the best way to do this?
Thanks,
Steve
Sure, you can simple select the birthdays for the current day in the WHERE
clause.
$current_date = getdate(); //www.php.net/getdate for reference
$bday_qry = "SELECT ";
$bday_qry.= "user_fname, user_lname, DATE_FORMAT(user_bday, '%m-%d') AS bday
";
$bday_qry.= "WHERE "
$bday_qry.= "MONTH(user_bday) = '" . $current_date['mon'] . "' AND
DAYOFMONTH(user_bday) = '" . $current_date['mday'] . "' AND YEAR(user_bday)
= '" . $current_date['year'] . "'";
That should do it I think =D.
--
Sharif T. Karim
....you don't know wrath yet...