51yvaq
Last Updated: March 16, 2017
·
89
· dpaluy
3129de6b479cc965513311f1ddcc268a

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)
Say Thanks
Respond