doddsey_65 Posted January 25, 2011 Share Posted January 25, 2011 im trying to generate a birthday list for people who have birthdays today. Unfortunatly it keeps coming up 0 when there are birthdays today. here is the query: $birthday_query = $link->query("SELECT u.u_username, u.u_birthday FROM ".TBL_PREFIX."users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '" . $link->asf_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' ORDER BY u_username ASC"); the query string is: SELECT u.u_username, u.u_birthday FROM asf_users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '25- 1-%' ORDER BY u_username ASC there is a birthday in the database which appears like: 25-1-1986 but it still says no birthdays. any ideas? and yes the user is confirmed and not banned. Quote Link to comment https://forums.phpfreaks.com/topic/225677-birthday-list/ Share on other sites More sharing options...
Pikachu2000 Posted January 25, 2011 Share Posted January 25, 2011 What is the field type that the birth date is stored in? Quote Link to comment https://forums.phpfreaks.com/topic/225677-birthday-list/#findComment-1165256 Share on other sites More sharing options...
doddsey_65 Posted January 26, 2011 Author Share Posted January 26, 2011 varchar(10) Quote Link to comment https://forums.phpfreaks.com/topic/225677-birthday-list/#findComment-1165261 Share on other sites More sharing options...
Pikachu2000 Posted January 26, 2011 Share Posted January 26, 2011 You really need to store dates and times in the appropriate field type. Then you can use the native MySQL date and time functions. SELECT `whatever` FROM `table` WHERE ( MONTH(`birthday`) = MONTH(CURDATE()) AND DAY(`birthday`) = DAY(CURDATE()) ) Quote Link to comment https://forums.phpfreaks.com/topic/225677-birthday-list/#findComment-1165267 Share on other sites More sharing options...
sasa Posted January 26, 2011 Share Posted January 26, 2011 change sprintf('%2d-%2d-', $now['mday'], $now['mon']) to sprintf('%d-%d-', $now['mday'], $now['mon']) Quote Link to comment https://forums.phpfreaks.com/topic/225677-birthday-list/#findComment-1165390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.