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)
Written by David Paluy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#