21

How to select records between a date to another date given a DateTime field in a table.

2
  • isn't it discussed/asked over here previously? Commented Dec 22, 2009 at 11:16
  • Look here: stackoverflow.com/questions/1443555/… Search rules! ;) Commented Dec 22, 2009 at 15:37

3 Answers 3

29
SELECT * 
FROM tbl 
WHERE myDate BETWEEN #date one# AND #date two#;
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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
22
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

0

select * from table name (exm.User) where column name (exm.Date) between '2022-10-10 08:00:00' and '2022- 10-11 12:00:00'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.