MySQL查询生日是今天的用户
select * from customer where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())
查询7天内生日的用户(这个不能跨年查询)
select * from customer
where DATE_FORMAT(birthday,'%m-%d') >= DATE_FORMAT(now(),'%m-%d')
and DATE_FORMAT(birthday,'%m-%d') <= DATE_FORMAT(date_add(now(), INTERVAL 6 DAY),'%m-%d')
补充:
解决跨年问题
select user_id , name , birth , user_type from sys_user
where birth >= DATE_FORMAT(now(),'%Y-%m-%d')
and birth <= DATE_FORMAT(date_add(now() , INTERVAL 6 DAY),'%Y-%m-%d')