wilna Posted May 9, 2011 Share Posted May 9, 2011 Hi, I hope someone can help me. I am trying to generate a script for our Intranet that tells me which birthdays = today. My field in my table = d/m/y, eg 09/05/2011 (9 May 2011). How do I get the script to just look at the day & month, not the year? My script looks like this: <?php echo date("d/m/Y") . "<br />"; $myDate = date('d/m/Y'); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql = "SELECT * FROM detail WHERE dob='$mydate'"; $result=mysql_query($sql); echo mysql_num_rows($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235919-dob-problems/ Share on other sites More sharing options...
jonsjava Posted May 9, 2011 Share Posted May 9, 2011 SELECT * FROM detail WHERE dob LIKE '$mydate%'; change mydate to $myDate = date('d/m/'); Quote Link to comment https://forums.phpfreaks.com/topic/235919-dob-problems/#findComment-1212758 Share on other sites More sharing options...
gristoi Posted May 9, 2011 Share Posted May 9, 2011 what is the data type for your dob field? If you used a date type then you can just do it all in one query SELECT * FROM detail WHERE dob = CURDATE() and if you use a datetime datatype: SELECT * FROM detail WHERE DATE(dob) = CURDATE() and if you wanted to get everyone who had a birthday tomorrow: SELECT * FROM detail WHERE DATE(dob) = DATE_ADD(CURDATE(), INTERVAL 1 DAY); etc..................... Quote Link to comment https://forums.phpfreaks.com/topic/235919-dob-problems/#findComment-1212760 Share on other sites More sharing options...
jonsjava Posted May 9, 2011 Share Posted May 9, 2011 That wouldn't work. That would only pull up people born tomorrow/today. He wants it a little more flexible. Babies excluded *lol* Quote Link to comment https://forums.phpfreaks.com/topic/235919-dob-problems/#findComment-1212761 Share on other sites More sharing options...
wilna Posted May 9, 2011 Author Share Posted May 9, 2011 thanks, the $myDate = date('d/m'); part works then I get today's date without the year, but my dob field in my table also have a year in so what must I do to get that fields value without the year? My dob field is just a date type field, does that help? Quote Link to comment https://forums.phpfreaks.com/topic/235919-dob-problems/#findComment-1212765 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.