At 14:56 +0200 12/27/02, Patrascu Eugeniu wrote:
>I have a problem calculating birthdays in sql. Here goes my setup:
>I have a database that contains the bithdays of a number of people,
>and I want to know when there birthday is to congratulate them.
>The thing is that I want to now that a day before their birthday.
>Therefore I need a way to do that, and I do not know how to do it,
>so I am asking on this list, maybe there is someone that can tell me
Compare the MONTH() and DAYOFMONTH() values of your birthday column
to the MONTH() and DAYOFMONTH() values for tomorrow's date, which you
can calculate using CURDATE() and DATE_ADD(). Something like this:
SET @tomorrow = DATE_ADD(CURDATE(),INTERVAL 1 DAY);
SELECT * FROM tbl_name
WHERE MONTH(birth) = MONTH(@tomorrow)
AND DAYOFMONTH(birth) = DAYOFMONTH(@tomorrow);