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.
Since this gets more and more to be a code-golf question, here's my approach on solving this including taking care of the leap years:
Explanation: The first where clause checks if somebody's birthday is today. The second makes sure to only select those whose birthday is on Feb 29th only if the current day equals the last day of February.
Examples:
You can use the query below if date of birth stored in a table.
Today Birthday :
Yesterday Birthday:
Tomorrow Birthday:
Here is an answer that property takes into account leap-years and will always give you the users whose birthday is on the 29th of February at the same time as those on the 1st of March.
I come across with this problem, and I just used this simple code using the
NOW();
The results are today's birthdays so after that I working in sending emails to my users on their birthday.
I store my users bithdays using just the DATE so I always have
yy:mm:dd
, so this works like a charm, at least to me, using this approach.Enjoy :)
This gives you a person's birthday calculated according the current year. Then you can use it for other calculations! The columns
isBirthday28Feb
andisThisYearLeap
are given just to illustrate the solution.This should work: