douyong1908 2013-05-11 21:36
浏览 256

查询MySql数据库,查看当前日期后30天内“生日”日期字段的条目

I am trying to write a PHP script that queries a MySql database and returns the entries for which the Birthday date field is within the next 30 days. I am able to do this, but I need to exclude the year from the Birthday date when making the query. For example, if today's date is 7/10/2013, and the birthday in question is 7/13/1991, obviously these two dates are more than 30 days apart, but if we exclude the year, they are only 3 days apart. Making this a valid Birthday to return.

The Birthday field is stored as a DATE in the MySql database.

The query I have made so far:

$results = mysql_query("SELECT * FROM Club WHERE Birthday < DATE_SUB(NOW(), INTERVAL 30 DAY)");

What can I do to modify this query to not take the year into account?

  • 写回答

4条回答 默认 最新

  • duanmeng9336 2013-05-11 21:51
    关注

    Is this what you're looking for?

    SELECT * FROM Club WHERE month(Birthday) = month(DATE_SUB(NOW(), INTERVAL 30 DAY)) and dayofmonth(Birthday) = dayofmonth(DATE_SUB(NOW(), INTERVAL 30 DAY));

    http://pastebin.com/uEXrXrHT

    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示