r0xette r0xette - 3 days ago 5
MySQL Question

query on date returning incorrect results

Why would this include those records also which are created on 2016-10-31? Shouldn't this be showing results after 10/31 and before 11/5?

Query



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


Output



'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'

Answer

Try this

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

Comments