i am making a query to get birthdays for next 10 days . i was able to make a query for today but even after referring some post was not able to make it for next 10 days. Here is the query i made to get birthdays for today
$count=mysql_query("SELECT u.fname, u.lname, u.profile_pic, u.uid, u.bday, f.uid,
f.friend_id, f.status FROM friend_list f, users_profile u
WHERE f.uid = '$id' AND f.status = '1'
AND u.uid = f.friend_id
AND DAY(STR_TO_DATE(u.bday, '%m-%d-%y')) = DAY(CURDATE())
AND MONTH(STR_TO_DATE(u.bday, '%m-%d-%y')) = MONTH(CURDATE())");
can anyone help me out with a query for 10 days
解决方案
If u.bday is a date, you can do something like this:
WHERE u.bday < NOW() + INTERVAL 10 DAY AND u.bday >= NOW()
MySQL has good date comparison and calculation functions. Refer to the manual for more details: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
If u.bday is a varchar formatted mm-dd-yyyy, use this:
WHERE STR_TO_DATE(u.bday, '%m-%d-%Y') < NOW() + INTERVAL 10 DAY
AND STR_TO_DATE(u.bday, '%m-%d-%Y') >= NOW()
(If u.bday is not a date, make it one. Using the right data type for your columns makes your life a lot easier.)