Arun Yadav Arun Yadav - 4 months ago 9
MySQL Question

Mysql query between and like query

I had a table in which dates are storing in datetime format like '2016-06-29 00:58:12'. I have to find the data between two dates but the problem is that i stored this with time also so how can i get the output ..

I tried

SELECT time_of_action FROM `trackvendoraction` where time_of_action like '2016-06-29%'
union
SELECT time_of_action FROM `trackvendoraction` where time_of_action like '2016-06-30%'


i this above query i got the data for two dates now i had to apply the between query . how can i do this ?
thanks

JPG JPG
Answer

Try this:

SELECT time_of_action 
FROM `trackvendoraction`  
WHERE time_of_action BETWEEN '2016-06-29 00:00:00' AND '2016-06-30 23:59:59'