Last Updated: March 16, 2017
·
1.12K
· dpaluy

Create “Upcoming birthdays” query in Rails and PostgreSQL?

Assuming you have a User model with birthday:datetime attribute.
In order to find all users with a birthday next month, do the following:

next_month = (Date.today + 1.month).month
users_having_birhtday_next_month = 
  User.where("EXTRACT(MONTH FROM birthday) = ?", next_month)