benji87 Posted January 17, 2008 Share Posted January 17, 2008 Can someone please correct me where im going wrong here please? This is my code for trying to pull results that have a event date between two dates: <? include "db.php"; $act_type = 'All'; $area = 'Portsmouth'; $start = '01/01/2008'; $end = '30/05/2008'; $query = mysql_query("SELECT * FROM events WHERE date BETWEEN '$start' AND '$end'"); while ($data = mysql_fetch_array($query)) { ?> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr> <td width="33%" bgcolor="#efefef"><?=$data["event"]?></td> <td width="47%" bgcolor="#efefef"><?=$data["date"]?></td> </tr> </table> <? } ?> For some reason it returns all records in the table rather than just the ones between the two dates. Thanks Link to comment https://forums.phpfreaks.com/topic/86438-between-sql-query/ Share on other sites More sharing options...
adam291086 Posted January 17, 2008 Share Posted January 17, 2008 some database treate the BETWEEN ....AND.. differently. Some database will do what your asking for and others will do the opposite. I.E. display all records that are not between those dates. Check your result echoed back and see if the opposite of what you want is happening Link to comment https://forums.phpfreaks.com/topic/86438-between-sql-query/#findComment-441719 Share on other sites More sharing options...
pdkv2 Posted January 17, 2008 Share Posted January 17, 2008 i have faced the similar problem it was due to the date field in the database was using '2008-12-30' format and we are trying to compare it with '30-12-2008' Rgds Sharad Link to comment https://forums.phpfreaks.com/topic/86438-between-sql-query/#findComment-441724 Share on other sites More sharing options...
benji87 Posted January 17, 2008 Author Share Posted January 17, 2008 In my case its just showing all the records in the table including the ones inside and out the dates ive specified. My field isn't setup as a date field. Its setup as a varchar. Would that affect it do you think? Link to comment https://forums.phpfreaks.com/topic/86438-between-sql-query/#findComment-441731 Share on other sites More sharing options...
Nhoj Posted January 17, 2008 Share Posted January 17, 2008 More than likely... Try setting the field to a date field... Edit: ..Also make sure all your date's are formatted correctly.. Link to comment https://forums.phpfreaks.com/topic/86438-between-sql-query/#findComment-441732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.