I just find mysql can query datetime using like:
like '2013-06-12%'
I think it can not use the index. I Google it, but can not find such subject directly. So I have a test using a table with 3308614 records. The first SQL:
SELECT * FROM subscription t WHERE DATE(t.active_time) = '2013-06-30';
All we know this SQL can not use the index and it takes 4 seconds to get the result. The second SQL:
SELECT * FROM subscription t WHERE t.active_time LIKE '2013-06-30%';
I don't know if it can use the index, but it takes 4 seconds too. The third SQL:
SELECT * FROM subscription t WHERE t.active_time > '2007-11-30' AND t.active_time < '2007-12-01';
All we know the third SQL can use the index, and it takes 0.016 second.
So I think 'like' can not use the index when query the datetime field, because mysql should convert datetime field to string first and send the string to like command. Is this correct ?