Reputation: 31
I need to find upcoming birthday from database table name users
and column name u_bday
where u_bday
is in varchar format.
i tried this but not work for me help.
$sql=" SELECT `f_name`,`u_bday` FROM `users`
WHERE DATE_ADD(`u_bday`, INTERVAL YEAR(CURDATE())-YEAR(`u_bday`)+
IF(DAYOFYEAR(CURDATE()) > DAYOFYEAR(u_bday),1,0) YEAR)
BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)";
what should i do???
Upvotes: 0
Views: 432
Reputation: 1637
You can use date_diff function and query could be somthing like below
SELECT `f_name`,`u_bday` FROM `users`
WHERE DATE_DIFF(`u_bday`, now()) > 1
ORDER BY u_bday asc;
Upvotes: 0
Reputation: 468
use this function to convert your varcher column to date format
str_to_date( fieldname, '%Y-%m-%d')
Upvotes: 1