开发者

Mysql Correctly compare 2 datetimes?

I have an issue that i'm about 开发者_StackOverflow中文版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!


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


Change your query to:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜