Jump to content

Mysql date comparison


developerdave

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/196461-mysql-date-comparison/
Share on other sites

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'  

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.