Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

mysql query to get birthdays for next 10 days

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...