Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all records between two datetime format

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

I tried this but it didn't work.

select * from cdr
 WHERE calldate BETWEEN '2012-12-01' AND '2012-12-03';
like image 600
al_alb Avatar asked Dec 03 '12 15:12

al_alb


People also ask

How can I get data between two dates in SQL Server?

You can use the dateadd function of SQL. This will return ID 1,2,3,4. We are doing a double Dateadd ; the first is to add a day to the current endDate , it will be 2012-03-28 00:00:00, then you subtract one second to make the end date 2012-03- 27 23:59:59.

Can we use between for dates in SQL?

The SQL BETWEEN Operator The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.


1 Answers

Try this instead:

select * from cdr
WHERE DATE(calldate) BETWEEN '20121201' AND '20121203';
like image 164
Mahmoud Gamal Avatar answered Sep 27 '22 20:09

Mahmoud Gamal