查询日期返回不正确的结果

时间:2016-11-30 21:14:02

标签: mysql

为什么这包括2016-10-31创建的那些记录?不应该在10/31之后和11/5之前显示结果吗?

查询

select distinct id, createdate 
from ticket_history 
where createdate > '2016-10-31' 
  and createdate < '2016-11-5'

输出

'14725', '2016-10-31 08:00:28'
'14726', '2016-10-31 08:32:29'
'14727', '2016-10-31 09:58:09'
'14728', '2016-10-31 10:27:38'
'14729', '2016-10-31 10:52:38'
'14731', '2016-10-31 14:01:42'
'14734', '2016-11-02 11:38:30'
'14735', '2016-11-02 14:02:57'
'14736', '2016-11-02 14:34:30'
'14742', '2016-11-03 14:08:44'
'14745', '2016-11-03 23:32:55'
'14746', '2016-11-04 08:34:18'
'14747', '2016-11-04 09:43:42'
'14748', '2016-11-04 12:32:56'
'14749', '2016-11-04 14:24:44'
'14750', '2016-11-04 16:53:44'

1 个答案:

答案 0 :(得分:1)

试试这个

select distinct id, createdate 
from ticket_history 
where date(createdate) > '2016-10-31' 
  and date( createdate) < '2016-11-5'