Reputation: 1
I am trying to display all users whose birthday is within this week (Monday to Sunday). After searching everywhere I was able to get this but it's displaying users from last week and this week also.
SELECT * FROM teachers WHERE WEEK(birthday, 0) = WEEK(NOW(), 0)
Upvotes: 0
Views: 248
Reputation: 43700
Change the second argument for the WEEK
function. I think that you want it to be either 3
or 5
. Based on the documentation.
Setting the mode to 0
would get people whose birthdays are on Sunday in the previous week based on what you are saying in your question.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
Upvotes: 1
Reputation: 11393
Use function WEEKOFYEAR:
SELECT * FROM teachers WHERE WEEKOFYEAR(birthday) = WEEKOFYEAR(NOW());
WEEKOFYEAR
returns a number in the range 1 to 53.
Upvotes: 0
Reputation: 2597
Check MySQL's function WEEKOFYEAR. You could use it like this to get users with birthday in current week:
SELECT * FROM teachers WHERE WEEKOFYEAR(birthday) = WEEKOFYEAR(NOW())
Upvotes: 0