我想发送通知邮件给今天生日不是的人。 我用代码找出今天过生日的人......
控制器代码:
@people = Person.find(:all, :conditions => ["DAY(date) = ? AND MONTH(date) = ?", Date.today.day, Date.today.month])
现在,如何修改它以获得生日人以外的其他人?
答案 0 :(得分:1)
@people = Person.where('DAY(date) <> ? OR MONTH(date) <> ?', Date.today.day, Date.today.month)
答案 1 :(得分:1)
当然应该是:
@people = Person.where('DAY(date) <> ? AND MONTH(date) <> ?', Date.today.day, Date.today.month)
使用OR会将当天和当月其他日期的其他月份的人排除在外。
答案 2 :(得分:0)
@people = Person.where("extract(month from date) != ? AND extract(day from date) != ?", Date.today.month, Date.today.day)