You must use the DAYOFYEAR function. Try this query -
SELECT buddy_auto_id , buddy_bday FROM table_name WHERE DAYOFYEAR(buddy_bday) - DAYOFYEAR(NOW()) > 0 ORDER BY DAYOFYEAR(buddy_bday) - DAYOFYEAR(NOW()) LIMIT 3;
So, this query only works for the current year.
EDITED request 2:
This works for all dates.
CREATE TABLE birtdays( buddy_auto_id INT(11) NOT NULL AUTO_INCREMENT, buddy_bday DATE DEFAULT NULL, PRIMARY KEY (buddy_auto_id) ); INSERT INTO birtdays VALUES (1, '2011-10-04'), (2, '2011-03-01'), (3, '2011-11-29'), (4, '2011-11-10'), (5, '2011-12-29'), (6, '2011-11-30'), (7, '2011-12-08'), (8, '2011-09-17'), (9, '2011-12-01'), (10, '2011-12-11'); SELECT buddy_auto_id, buddy_bday FROM birtdays, (SELECT @day_of_year:=DAYOFYEAR(NOW())) t ORDER BY DAYOFYEAR(buddy_bday + INTERVAL YEAR(NOW()) - YEAR(buddy_bday) YEAR) - @day_of_year + IF (DAYOFYEAR(buddy_bday + INTERVAL YEAR(NOW()) - YEAR(buddy_bday) YEAR) - @day_of_year > 0, 0, DAYOFYEAR(STR_TO_DATE(CONCAT(YEAR(NOW()), '-12-31'), '%Y-%m-%d'))) LIMIT 3; +
source share