Select all records between two date and time formats

I have this query, I need to select all records between two dates, the mysql table is the date format.

I tried this, but it did not work.

select * from cdr WHERE calldate BETWEEN '2012-12-01' AND '2012-12-03'; 
+6
source share
3 answers

Try this instead:

 select * from cdr WHERE DATE(calldate) BETWEEN '20121201' AND '20121203'; 
+11
source

Try this query -

 SELECT * FROM cdr WHERE calldate BETWEEN str_to_date('2012-12-01','%Y-%m-%d') AND str_to_date('2012-12-03','%Y-%m-%d'); 
+1
source

The above will work just fine. If you want to add additional conditions, the normal logic works with date / time, so you can do something like

 ... where DATE(calldate) < '20121201' AND DATE(calldate) >= '20121203' OR DATE(calldate) = '20121205' 

A simple example.

-1
source

All Articles