How to select records between a date to another date given a DateTime field in a table.
Asked
Active
Viewed 1.6e+01k times
19
-
isn't it discussed/asked over here previously? – Saar Dec 22 '09 at 11:16
-
Look here: http://stackoverflow.com/questions/1443555/sql-syntax-select-results-for-each-date-between-a-range-of-dates Search rules! ;) – ThinkJet Dec 22 '09 at 15:37
2 Answers
28
SELECT *
FROM tbl
WHERE myDate BETWEEN #date one# AND #date two#;
-
2between is terribly misunderstood. casting of dattime to date happens intentionally and unintentionally. Personally I like explicit >= and <= because it does not save much typing but is so much less readable. – Richard Nov 06 '19 at 03:37
-
SELECT * FROM bookings WHERE item_id=2884 AND (start_date BETWEEN '2020-09-05 23:31:45' AND '2020-09-06 00:00:00' OR end_date BETWEEN '2020-09-05 23:31:45' AND '2020-09-06 00:00:00') ) This is my code, but it doesnt work well – ExpertWeblancer Sep 05 '20 at 06:35