zimminy Posted February 12, 2008 Share Posted February 12, 2008 Hi I am trying to ask MySQL for records that fall between dates like this: $FromDate='2008-01-01'; $ToDate='2008-02-15'; $query="SELECT * FROM orders WHERE datepaid BETWEEN $FromDate and $ToDate"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; echo '<br>The resulting rows were '.$num.'<br>'; And I made sure there were dates in the database that do fall within that range. And the table field called "datepaid" is a "date" field in MySQL, not just a text field But I still come up with zero rows returned. I looked to see if there was a known bug for the BETWEEN statement and also tried WHERE datepaid>$FromDate and datepaid<$ToDate but that didn't work either. Any help is much appreciated!!!!!!! Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/ Share on other sites More sharing options...
awpti Posted February 12, 2008 Share Posted February 12, 2008 So.. what's it do when you run it from the console? Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/#findComment-464528 Share on other sites More sharing options...
zimminy Posted February 12, 2008 Author Share Posted February 12, 2008 I don't run the server. So I make PHP pages, upload them and figure it out from there. Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/#findComment-464531 Share on other sites More sharing options...
toplay Posted February 12, 2008 Share Posted February 12, 2008 You forgot the quotes around the date values: $query="SELECT * FROM orders WHERE datepaid BETWEEN '$FromDate' and '$ToDate'"; Always check for any possible errors after a query, and before executing any subsequent commands (like mysql_num_rows). If you had, it would have indicated to you the syntax problem in your query. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/#findComment-464555 Share on other sites More sharing options...
zimminy Posted February 12, 2008 Author Share Posted February 12, 2008 Thanks!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/#findComment-464640 Share on other sites More sharing options...
zimminy Posted February 12, 2008 Author Share Posted February 12, 2008 How do I mark this as "solved"? Quote Link to comment https://forums.phpfreaks.com/topic/90604-query-mysql-with-date-between-this-and-that-not-working/#findComment-464642 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.