获取未来一个月生日的mysql,mysql查询以获取未来10天的生日

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值