rvdb86 Posted March 12, 2009 Share Posted March 12, 2009 Hi, I hope this is possible! I have a table with a field the field reg_date which has a DATE format. I want to select all the fields from the table where the m = date("m") and the d = $d where $d is populated by a while loop. Any suggestions? TIA! Quote Link to comment https://forums.phpfreaks.com/topic/149150-solved-select-dates-from-table-by-day/ Share on other sites More sharing options...
MadTechie Posted March 12, 2009 Share Posted March 12, 2009 Huh! you lost me, Okay you want to select all fields (SELECT * FROM table WHERE the month is what and the day is what ? do you mean a range! you totally lost me! Quote Link to comment https://forums.phpfreaks.com/topic/149150-solved-select-dates-from-table-by-day/#findComment-783289 Share on other sites More sharing options...
samshel Posted March 12, 2009 Share Posted March 12, 2009 <?php $arrDays = array(); while() { //populate days $arrDays[] = $something; } $sql = "SELECT * FROM table WHERE MONTH(reg_date) ='".$m."' AND DAY(reg_date) IN ('".implode("','", $arrDays).'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/149150-solved-select-dates-from-table-by-day/#findComment-783336 Share on other sites More sharing options...
MadTechie Posted March 12, 2009 Share Posted March 12, 2009 Slight bug in your code samshel (easily missed), Heres the fix.. $sql = "SELECT * FROM table WHERE MONTH(reg_date) ='".$m."' AND DAY(reg_date) IN ('".implode("','", $arrDays)."')"; Quote Link to comment https://forums.phpfreaks.com/topic/149150-solved-select-dates-from-table-by-day/#findComment-783350 Share on other sites More sharing options...
rvdb86 Posted March 17, 2009 Author Share Posted March 17, 2009 sorry for the late reply, but thanks so much for your help works perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/149150-solved-select-dates-from-table-by-day/#findComment-786754 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.