I have all users' birthdays stored as a UNIXtimestamp and am wanting to send out e-mails each day to users that have a birthday that day.
I need to make a MySQL query that will get all of the rows that contain a birthday on today's date.
It seems like this should be fairly simple, but maybe I am just overcomplicating it.
The answer below doesn't actually work. It doesn't take into account the fact that a year is 365.24 (leap days now and then) days long, so the actual comparison against the users birthdate is complicated to say the least. I'm leaving it for historical reasons.
Here's my contribution
The bits '(dayofyear(date_format(current_date,'%Y-03-01'))-60)' returns 1 on leap years since march 1st will be dayofyear number 61, and 0 on normal years.
From here it's just a matter of substracting that extra day to the "is-it-my-birthday"-calculation.
Couldn't you just select all rows that matched the current day's date? You could also use the FROM_UNIXTIME() function to convert from unix timestamp to Date:
mysql> SELECT FROM_UNIXTIME(1196440219); -> '2007-11-30 10:30:19'
This is documented from http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime
I took Saggi Malachi's answer and extended to include a birthday on 29th February into 28th February date, if in that year there is no such day.
This should cover the leap year cases, and uses the internal date mechanics.
Basically it works by adding the years between the two dates to the date of birth and checks for equality with the current date:
Testing: