How to create “Upcoming birthdays” module in Rails?

后端 未结 9 2258
栀梦
栀梦 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

    Here's how I find today's birthdays:

    User.find_by_sql("select * from users where date_format(date_of_birth, '%m%d') = date_format(now(), '%m%d')")

    I run this once a day. It takes less than a second from about 100,000 rows. (It doesn't properly handle people born on Feb 29th.)

提交回复
热议问题