2011-07-18 88 views
0

我有一个表,其中包含ID的列表(int)和创建ID的日期(日期时间)。MySQL日期匹配错误?

一个ID尤其是被创造:

2010-12-31 9点45分29秒

当我运行下面的查询,不返回任何结果:

select * from information where creation = '2010-12-31' 

是什么给了?我认为这是因为时间戳(它不匹配2010-12-31 00:00:00),但似乎它应该作为一般'日期'。

+2

重复http://stackoverflow.com/questions/4973268/mysql-date-and-datetime-problem – Ergec

回答

3
select * from information where DATE(creation) = '2010-12-31' 

你自己,2010-12-31 = 2010-12-31 00:00:00,这不等于说2010-12-31 09:45:29它。您可以使用DATE()确保您比较苹果和苹果

+0

了它 - 感谢您的帮助。我不知道我需要在sql调用中明确声明日期函数。感谢帮助 – JM4

0

不,不应该。尝试运行

select * from information where creation LIKE '2010-12-31%'; 

select * from information where DATE(creation) = '2010-12-31' 
0

试试这个:

select * from information where DATE_FORMAT(creation,'%Y-%m-%d') = '2010-12-31'