William
William

Reputation: 1033

Mysql Correctly compare 2 datetimes?

I have an issue that i'm about to pull my hair out over, ok let me start.

I'm using php and mysql i have a database that holds rows with information and one of the columns has a datetime field in a 24hr format.

I am trying to retrieve information using the following query:

SELECT * FROM `table` 
where `new` != '1' 
AND `time` >= '2010-08-27 22:04:37' 
AND `name` LIKE '%apple%' 
OR `name2` LIKE '%apple%'

My expectations of this query would be to retrieve everything from table where time is greater than or equal to 2010-08-27 22:04:37 . Which I thought would return everything from 2010-08-27 22:04:37 up 2010-08-28 etc. but i'm receiving rows with dates of

2010-08-26 04:59:34
2010-08-26 03:00:00
2010-08-26 23:00:00

Could someone help me please. Thanks in advance!

Upvotes: 0

Views: 94

Answers (2)

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25370

SELECT * FROM `table` 
where `new` != '1' 
AND `time` >= '2010-08-27 22:04:37' 
AND  (`name` LIKE '%apple%' 
     OR `name2` LIKE '%apple%')

Upvotes: 1

Anax
Anax

Reputation: 9362

Change your query to:

... where new != '1' AND time >= '2010-08-27 22:04:37' AND 
(name LIKE '%apple%' OR name2 LIKE '%apple%')

Upvotes: 1

Related Questions