数据库设计
is_lunar 是否农历(0=阳历、1=农历)birthday 生日(date类型 直接存生日 格式 1985-07-19)问题
查询出今天过生日的记录集应该怎么写?ps:mysql的日期函数知识几乎为0,不知道怎么写,望兄弟们不吝赐教,万分感激。

解决方案 »

  1.   

    select * from table where birthday=current_date();
      

  2.   


    版主大大啊 current_date()是当前时间带年的啊 2017-04-11 这样啊而数据库里存的生日是 1985-04-11 这样啊,肯定比对不上的吧
      

  3.   

    select * from table where date_format(birthday, '%m-%d')=date_format(current_date(), '%m-%d')
      

  4.   

    select * from table where ( is_lunar = 0 and date_format(birthday, '%m-%d') = {$solar} ) or ( is_lunar = 1 and DATE_FORMAT(birthday,'%m-%d') = {$lunar}) 
    最后的sql是这样的对吧
      

  5.   

    既然is_lunar = 0,1的都出来,那就可以把这个条件去掉
      

  6.   


    去掉不了,因为找到is_lunar = 0的数据 查询的时间是阳历的 月日找到is_lunar = 1的数据查询时间是阴历的月日