How to select records between a date to another date given a DateTime field in a table.
3 Answers
SELECT *
FROM tbl
WHERE myDate BETWEEN #date one# AND #date two#;
2 Comments
Richard
between 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.
ExpertWeblancer
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
select *
from blah
where DatetimeField between '22/02/2009 09:00:00.000' and '23/05/2009 10:30:00.000'
Depending on the country setting for the login, the month/day may need to be swapped around.
1 Comment
törzsmókus
PSA: xkcd.com/1179