Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting between two dates within a DateTime field - SQL Server

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

like image 980
bala3569 Avatar asked Dec 22 '09 11:12

bala3569


People also ask

How do I select between two dates in SQL?

Here, first add a day to the current endDate, it will be 2011-02-28 00:00:00 , then you subtract one second to make the end date 2011-02-27 23:59:59 . By doing this, you can get all the dates between the given intervals.

How do I select a specific date range in SQL?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2001-03-01 11:00:00' AND '2005-03-01 22:00:00';

How do I use between datetime?

date and time. For example instead of between '02/03/2011' and '05/03/2011' it should be between '02/03/2011 00:00:01' and '05/03/2011 23:59:59' ... Date AND Time.


2 Answers

SELECT * 
FROM tbl 
WHERE myDate BETWEEN #date one# AND #date two#;
like image 170
Oded Avatar answered Oct 01 '22 11:10

Oded


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.

like image 45
Tikeb Avatar answered Oct 01 '22 11:10

Tikeb