developerdave Posted March 25, 2010 Share Posted March 25, 2010 Hey guys, I'm getting pretty frustrated with this now, I am trying to select products from a table that are in the future only (items that haven't expired) but all the date comparison's I try just seem to return the past dated items as well as future items. SELECT `item_id`,`item_name`,`item_owner`,`item_condition`,`item_price`,`item_end_time`,xxxxxxxxx_school.school_name FROM `xxxxxxxxxxx_item` LEFT JOIN `xxxxxxxxxx_school` ON `school2school_item`.`item_owner`=`xxxxxxxxx_school`.`school_id` WHERE `item_name` LIKE '%mac%' OR `item_description` LIKE '%mac%' AND `item_end_time` > '2010-03-25 09:30:43' ORDER BY `item_end_time` ASC LIMIT 0,5; I was asked to hide the company name, but thats the query that I'm trying to write/run, I've tried using UNIX_TIMESTAMP() and checked the data types on the datetime field (item_end_time) but it always returns dates that have been and gone. Any idea's anyone? Quote Link to comment https://forums.phpfreaks.com/topic/196461-mysql-date-comparison/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 25, 2010 Share Posted March 25, 2010 Your WHERE clause contains a logical OR. What do we know about a TRUE value OR'ed with anything? It is TRUE. You need to use () in your logical statement to force the Operator Precedence that you want. I'll guess you actually want this for the WHERE part of the query - WHERE (`item_name` LIKE '%mac%' OR `item_description` LIKE '%mac%') AND `item_end_time` > '2010-03-25 09:30:43' Quote Link to comment https://forums.phpfreaks.com/topic/196461-mysql-date-comparison/#findComment-1031549 Share on other sites More sharing options...
developerdave Posted March 25, 2010 Author Share Posted March 25, 2010 Well. That was just annoyingly simple Cheers man, worked a treat! Quote Link to comment https://forums.phpfreaks.com/topic/196461-mysql-date-comparison/#findComment-1031552 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.