Several answers suggested calculating / saving the day of the year and sorting them out, but this alone will not bring much benefit when you are approaching the end of the year, and you need to consider people with birthdays at the beginning of next year.
I would choose a solution in which you calculate the full date (year, month, day) of each person on the next birthday, and then sort by this question. You can do this in Ruby code or use a stored procedure in a database. The latter will be faster, but will make your application more difficult to switch to another db platform later.
It would be wise to update this list of upcoming birthdays once a day, which means that you can use some form of caching. So the speed of the requested request / code is not a problem, and something like this should work fine while you cache the result:
class User def next_birthday year = Date.today.year mmdd = date_of_birth.strftime('%m%d') year += 1 if mmdd < Date.today.strftime('%m%d') mmdd = '0301' if mmdd == '0229' && !Date.parse("#{year}0101").leap? return Date.parse("#{year}#{mmdd}") end end users = User.find(:all, :select => 'id, date_of_birth').sort_by(&:next_birthday).first(5)
Edit : Fixed correct execution with leap years.
source share