0

I've been looking for a solution here in the community, but I have not found anything specific. I need to do searches for birthdays among a period using only the month and month day (excluding year). I have users with their birthdays registered in date fields in my MySQL.

Name | Dt. Birth
Julian | 1990/01/18
Luiz | 2000/02/15
Morgana | 1973/02/01

I need to realize two different tasks.

1st - Let's suppose today date is February 01. How could I take today's date and decrease 14 days, searching for users whose birthday was on previous 2 weeks? (only Julian would be listed).

Another query will list users whose birthday is today (only Morgana would be listed).

And a third one should list the birthdays within next two weeks (only Luiz would be listed) I was using these code, but they don't seem to work at all times.

select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())-14 and DAYOFYEAR(CURDATE())-1;
select * from user where DAYOFYEAR(dateBirth) = DAYOFYEAR(CURDATE());
select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())+1 and DAYOFYEAR(CURDATE())+14;


2nd - In a form, I will select two days and months
|01||January |
|15||February|
and the users whose birthday is within this range will be listed. (All users listed)

Maybe this fiddle help you visualize the question. http://www.sqlfiddle.com/#!9/1dec7a/5
I reproduce the above queries that show some inaccuracy. If you change values (-14/+14 and (-1/+1), you shall be able to list the users.

Guilhermy
  • 55
  • 6

0 Answers0