求 sql 最近5天过生日 需要考虑到 用户生日在 12月29日 情况 及闰年情况

解决方案 »

  1.   

    $sql="select * from Table where DateDiff(day‚ CreateTime‚ getdate())<5";具体的根据情况修改一下
      

  2.   

    select * from user where birthday <> '' and ( DATEDIFF( concat( year( now( ) ) , DATE_FORMAT( birthday, '-%m-%d' ) ) ,date( now( ) ) ) <=5 or DATEDIFF(date( now( ) ), concat( year( now( ) )-1 , DATE_FORMAT( birthday, '-%m-%d' ) ) ) <= 5 ) order by id desc 
      

  3.   

    最近5天 过完生日的算不算。如果不算的话直接用in查询好了 
    date_format(bd,'%m-%d') in (1,2,3,4,5)哈哈