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';
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.
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.
Try this instead:
select * from cdr
WHERE DATE(calldate) BETWEEN '20121201' AND '20121203';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With