How to create “Upcoming birthdays” module in Rails?

后端 未结 9 2185
栀梦
栀梦 2020-12-29 17:46

I have a table \"users\" with a column \"date_of_birth\" (DATE format with day, month, year). In frontend I need to list 5 upcoming birthdays.

Spent ages trying to w

9条回答
  •  醉梦人生
    2020-12-29 18:04

    Thanks to this post in my rails 3 app i use:

     u = User.where("strftime('%m%d', date_of_birth) = ?", Date.today.strftime('%m%d'))
    

    Update:

    To use this with Postgresql:

    u = User.where("extract(month from date_of_birth) = ? AND extract(day from date_of_birth) = ?", Date.today.strftime('%m'), Date.today.strftime('%d'))
    

提交回复
热议问题