生日那天通知别人

时间:2013-01-18 06:01:18

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2

我想发送通知邮件给今天生日不是的人。  我用代码找出今天过生日的人......

控制器代码:

@people = Person.find(:all, :conditions => ["DAY(date) = ? AND MONTH(date) = ?", Date.today.day, Date.today.month])

现在,如何修改它以获得生日人以外的其他人?

3 个答案:

答案 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)