Search code examples
mysqltimestampunix-timestamp

Use MySQL to determine whether today is a user's birthday


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.


Solution

  • This should work:

       SELECT * 
          FROM USERS
          WHERE 
             DATE_FORMAT(FROM_UNIXTIME(birthDate),'%m-%d') = DATE_FORMAT(NOW(),'%m-%d')