7

In my database, there is a field called birthday(date) and I want to retrieve records that their birth month and birth day is equal to the current month and the day. Is there a way to write a query for this? Or I just have to do it by retrieving all of the records and find the matching records after by using another program? Thanks!

2 Answers 2

14

This might also work: (NOTE that I am not sure if you mean day within a Month or day within a week)?

SELECT * FROM TABLE
WHERE MONTH(birthday) = MONTH(CURRENT_DATE)
AND DAY(birthday) = DAY(CURRENT_DATE)    --assuming day within a month
Sign up to request clarification or add additional context in comments.

1 Comment

Also checkout this stackoverflow.com/q/508791/247184 - its got some pointers.
5
select * from table
where date_format(birthday, '%m%d')=date_format(current_date, '%m%d');

The above query would not make use of mysql index

1 Comment

%y => Wouldn't it be %d instead ? here you are comparing year and month where day & month is asked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.