I have a table of users which has a date field for their birthday:
buddy_auto_id int(11) PK
user_id varchar(128)
buddy_user_id varchar(128)
buddy_name varchar(128)
buddy_bday date
buddyuser_id varchar(20)
active enum('Yes','No')
requestsentby int(11)
whenrequested timestamp
I’m trying to find the 3 users whose birthdays fall soonest compared to todays date and then display the number of days until their birthday ordered by soonest first.
Is this possible within a SQL query or do I have to pull it out and let PHP do the equation?
Many thanks
This should be possible with SQL. You need to compare the current date with a birthday expressed as from this year or next year, depending on whether we’ve past it in the current year. Once you have this “next birthday” date, use
DATEDIFFfunction to determine number of days distant from current date.