I have received a task from a client who wants some changes in his ongoing application. There is a table called users which has a field called birthdate. The previous developer was an idiot who saved the birthday varchar(255)
instead of datetime
. The data in the birthday column is saved as January 01, 1986
.
I want to fetch all the users whose birthday is in current date.
I tried to use:
$query = "SELECT * FROM users WHERE
DAY(STR_TO_DATE(birthday, '%Y-%m-%d')) = '".date('d')."'
AND MONTH(STR_TO_DATE(birthday, '%Y-%m-%d')) = '".date('m')."'";
But it is returning empty set of data. How can I fix this?